简体   繁体   中英

How can I parse DefineConstants value in a BeforeBuild target?

Related to this question .

What I really want of a way of setting key value pairs that is settable from the Vis Studio 2010 IDE. I seem not to be able to set Project property values from within the IDE so I am looking at using compiler constants.

So, if I have the compiler constants set to

 <DefineConstants>Foo=bar;Key=Value 2;</DefineConstants>

can I parse this (in a BeforeBuild target say) so that I can extract the values of "bar" and "Value 2"? My MSBuild skills are next to nothing and my Google foo has not found any solutions.

You can override this value when compiling the project with MSBuild.

 msbuild.exe myproj.csproj /p:DefineConstants="foo=true"

You can't set build properties in a BeforeBuild task, but you can read them using:

 $(DefineConstants)

This would return the raw string, and you would need to parse the string using batch commands to separate them into key/value pairs in a BeforeBuild step.

Not really sure what you are trying to do, DefineConstants are just that, and referenced in code for conditional compilation. If you want to add custom build properties you can edit the csproj file and include your own targets file. It depends where and why you want to access them. In the build process the IDE (plugin), or code?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM