23 เมษายน 2555 19:15
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?
23 เมษายน 2555 21:04เจ้าของ
no, at the moment we do not have this feature.
- เสนอเป็นคำตอบโดย Francesco LogozzoMicrosoft, Owner 23 เมษายน 2555 21:04
24 เมษายน 2555 0:51
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:
24 เมษายน 2555 9:50
As Francesco said it doesn't have this feature.
When I try I get this
CodeContracts: MyClass: Cannot load assembly '$(CCAnalysisOptionsEnvVar)'
24 เมษายน 2555 15:09
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:
26 เมษายน 2555 10:44
thanks for that explaination, very informative. I didn't know that VS would evaluate the env var in that way.