✅ Get build output directory at compile time?

The current project I'm working on is a set of plugins to be run inside another application. When I first started, I would have to relaunch the application every time I made a change to my code, which took a while. Since then, I've added a new plugin to the DEBUG build of the project which monitors the Visual Studio output directory and, if it notices a change in any of the DLL files, will find and reload the plugin that changed without restarting the application. This has been a huge help. Now, in this plugin is the absolute path of the directory to monitor
public string buildDirectory = "C:\\Users\\Temp\\.......\\bin\\Output";
public string buildDirectory = "C:\\Users\\Temp\\.......\\bin\\Output";
This has worked great while on my desktop PC, but I'd like the ability to work on the project while on my laptop or other device. Ideally, this workflow would just involve pulling/pushing from GitHub w/o needing to manually change this one string on each device. Does Visual Studio have something like a OUTPUT macro that evaluates to the build directory at compile time or something of that nature? (yes, I know C# doesn't have C-style macros so this probably isn't the right terminology) And/or could I store the the value in something like path.txt which is in my .gitignore and is substituted into the string as a precompiler step or something of that nature? I don't think there's a way to do it at runtime, because the assembly won't be run in the build directory... Thanks!
3 Replies
WEIRD FLEX
WEIRD FLEX8mo ago
there is a variable in msbuild that is the location of the project, so you could print that in a cs file for example but maybe there are easier ways to do this? i'm not saying like make a symbolic link, but maybe just a post-compilation step to copy the dll plugin in a common plugin folder?
乙ᗰᗩᑎ350᙭
I ended up making a T4 template BuildDirectory.tt containing
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#
string path = this.Host.ResolvePath("bin\\Output");
#>
namespace PUT_NAMESPACE_OF_PROJECT_HERE
{
public class BuildDirectory
{
public static string path = @"<#= path #>";
}
}
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#
string path = this.Host.ResolvePath("bin\\Output");
#>
namespace PUT_NAMESPACE_OF_PROJECT_HERE
{
public class BuildDirectory
{
public static string path = @"<#= path #>";
}
}
And then added the output BuildDirectory.cs to the gitignore and added some properties to the csproj to make it rebuild automatically you should just be able to clone the repo onto a new device, build the project, anc have it work out of the box
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts