SLN extension represents a Visual Studio solution file that keeps information about the organization of projects in a solution file. The contents of such a solution file are written in plain text inside the file and can be observed/edited by opening the file in any text editor.
In Visual Studio 2019 right-click your project, choose Properties . In the project properties window, select the Debug tab. Then, under Environment variables change the value of your environment from Development to Production or other environments.
The . sln file contains text-based information the environment uses to find and load the name-value parameters for the persisted data and the project VSPackages it references. When a user opens a solution, the environment cycles through the preSolution , Project , and postSolution information in the .
A user-defined macro is stored in a property sheet. If your project doesn't already contain a property sheet, you can create one by following the steps under Share or reuse Visual Studio project settings.
Just use the environment variable in the relevant field:
OutputDirectory="$(MyEnvVariableName)\Bin"
One trick is that you need to restart the Visual Studio IDE each time you change the variable.
There is an MSDN article precisely about this: How to: Use Environment Variables in a Build
I think I have the same goal than you: I want to use environment variables to locate some projects in a solution file (.sln) and to use some environment variables to locate some files within my projects.
I found a way to do that and it works fine for me (with Visual Studio 2005): - edit the .sln file with a text editor and use environment variables with the following syntax %MyEnvironmentVariable% - edit the .vcproj files and replace the path to the desired files with some variables, with the following syntax $(MyEnvironmentVariable).
Hope it helps... Cyrille
The best way to achieve what you describe in b) is to use property sheets. Check out also this very similar question.
I found some promising info on property sheets, but Visual studio doesn't expand macros when I am using them in File tag in the .vcproj.
I am not sure what version of VS you use. VS2008 lets you define for example an include directory like this: "$(OpenCVInclude)\cxcore\include". I use it all the time. OpenCVInclude is a macro defined in a property sheet.
As for question a), I think there is no "clean" way to do what you want. As an alternative you could the configuration manager:
I am not sure if you are building just C++ projects or if you are also building C#\VB projects, but one of the great things about Visual Studio is all of the projects are really just MSBuild projects. If you edit a project in a text editor you will see that at the end of the project it imports a .targets file. If you track down and find follow the imports you will find that almost all of the VS projects import Microsoft.Common.Targets. Microsoft.Common.Targets imports Custom.Before.Microsoft.Common.Targets. Using this import you can import your own targets file with your own custom actions.
I for example have a target file that has a common property defined across all projects in a solution and a custom post build event that processes at the end of each project building.
Using this extension method and by creating custom configurations in the solution besides just the standard release\debug, you should be able to create as complex of a build configuration as you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With