如何解析 BeforeBuild 目标中的 DefineConstants 值?
与此问题相关。
我真正想要的是一种设置可从 Vis Studio 2010 IDE 中设置的键值对的方法。我似乎无法从 IDE 中设置项目属性值,因此我正在考虑使用编译器常量。
那么,如果我将编译器常量设置为,
<DefineConstants>Foo=bar;Key=Value 2;</DefineConstants>
我可以解析它(在 BeforeBuild 目标中),以便我可以提取“bar”和“Value 2”的值吗?我的 MSBuild 技能几乎为零,我的 Google foo 也没有找到任何解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 MSBuild 编译项目时可以覆盖此值。
您无法在 BeforeBuild 任务中设置构建属性,但可以使用以下方式读取它们:
这将返回原始字符串,并且您需要使用批处理命令解析字符串,以在 BeforeBuild 步骤中将它们分成键/值对。
不太确定您要做什么,DefineConstants 就是这样,并在条件编译的代码中引用。如果您想添加自定义构建属性,您可以编辑 csproj 文件并包含您自己的目标文件。这取决于您想要访问它们的位置和原因。在构建过程中使用IDE(插件)还是代码?
You can override this value when compiling the project with MSBuild.
You can't set build properties in a BeforeBuild task, but you can read them using:
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?