I want to be able to pass cache settings via an environment variable.
CodeContractsExtraAnalysisOptions=-cache -cacheServer localhost
I've tried using
- %CodeContractsExtraAnalysisOptions%, this generates an error
- $CodeContractsExtraAnalysisOptions, this doesn't seem to do anything.
Is this possible? If so, how?
MSBuild supports environment variables with the following syntax:
I don't know whether you'll be able to set this option in the properties window, but you should be able to edit the project file manually. It should look something like this:
I just tested it myself and it works fine as long as you edit the project file manually, as mentioned previously.
Editing the Extra Static Checker Options field in the properties window doesn't work if you do it directly because it XML-encodes the value in the project file.
Here's what I did to get it working:
- Add a new environment variable with the name CCAnalysisOptionsEnvVar
and specify an appropriate value; e.g., I used the following value:
-show progress -outputwarnmasks
- Open your project file in a text editor; e.g., right-mouse click the project in Solution Explorer and select Unload, then right-mouse click again and select Edit.
- Find the CodeContractsExtraAnalysisOptions element within the PropertyGroup that contains the desired
Configuration and Platform settings and then update it as follows:
- Restart Visual Studio. This is required to make sure that the new environment variable is read into the process.
Now if you open the properties window you'll see that the value from the environment variable is shown in the Extra Static Checker Options field instead of the variable name. This is because MSBuild evaluates the variable before passing it to the CC extension.
Warning: Editing other CC settings in the properties window may cause you to lose all manual changes you've made within the project file.
It'd be great if CC preserved manual settings instead of overwriting them when saving changes to other settings.
- Add a new environment variable with the name CCAnalysisOptionsEnvVar and specify an appropriate value; e.g., I used the following value: