Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining Project Paths in a Solution via Macro/Environment Variable

Is there a way to define the project file path in a solution using a user macro/environment variable? I can't seem to do that.

Kind of like an environment variable is used to define the additional include directories in a C++ project, except I want to do the same for the location of a project file in a solution.

I've tried editing the solution in a text editor to change the path to start with %MyMacroName% or $(MyMacroName) but neither of them seems to parse just right. The project files can't be located when the solution is opened.

like image 330
Sion Sheevok Avatar asked May 19 '12 21:05

Sion Sheevok


People also ask

How do I add a path to environment variable in Visual Studio?

To add a path to the PATH environment variableIn the System dialog box, click Advanced system settings. On the Advanced tab of the System Properties dialog box, click Environment Variables. In the System Variables box of the Environment Variables dialog box, scroll to Path and select it.

How do I add a path to a Visual Studio project?

In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.

How to use Environment Variables in MSBuild?

To use an environment variable in an MSBuild project You can use a Condition attribute to provide a default value for a property if the environment variable was not set.

Where are macros defined in Visual Studio?

View the current properties and macrosSelect Edit and then in the Edit dialog box, choose the Macros button. The current set of properties and macros visible to Visual Studio is listed along with the current value for each.


2 Answers

In .sln file use syntax "%ENV_VAR%rest_of_the_path\test.csproj"

In .csproj file use syntax "$(ENV_VAR)rest_of_the_path\test.dll"

That works for me, ENV_VAR is custom environment variable defined for operating system like ENV_VAR = "C:\MyPath\"

like image 162
watbywbarif Avatar answered Oct 06 '22 12:10

watbywbarif


MSBuild allows you use to environment variables,

http://msdn.microsoft.com/en-US/library/ms171459(v=VS.80).aspx

So that you should be able to define environment variables as you wish, and then modify vCxproj files to make use of them.

I am not sure if that tip works for sln files, as sln files are not MSBuild scripts.

like image 33
Lex Li Avatar answered Oct 06 '22 13:10

Lex Li