开发者

How can I parse DefineConstants value in a BeforeBuild target?

开发者 https://www.devze.com 2023-04-09 19:07 出处:网络
Related tothis question. What I really want of a way of setting key value pairs that is settable from the Vis Studio 2010 IDE.I se开发者_如何学编程em not to be able to set Project property values fro

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 se开发者_如何学编程em 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号