MSBuild:永久更改项目的PropertyGroup属性 [英] MSBuild: Permanently Change PropertyGroup Property of a Project

查看:1264
本文介绍了MSBuild:永久更改项目的PropertyGroup属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望找到一种方法在我的csproj文件中设置一个值。在MSBuild中有一个任务,我可以用来将一个属性永久设置为一个值?在下面的示例中,是否可以永久设置CustomValue = Yes?

I was hoping to find a way to set a value in my csproj file during my build to a value. Is there a task in MSBuild that I can use to set a property permanently to a value? In the example below, can I set CustomValue = Yes permanently?

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    .....
    <CustomValue>XXXX</CustomValue
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids></ProjectTypeGuids>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
  </PropertyGroup>


推荐答案

您可以使用XmlPoke任务。看起来有点奇怪的是改变项目这种方式。或者,您可以在您的主项目文件中的PropertyGroup下设置一个小的导入文件

You can use the XmlPoke task to do that. It seems a little odd to be altering projects this way though. Alternatively, you can set up a tiny import file,

<!-- in your main project file, right below the PropertyGroup -->
<Import
  Condition="Exists('Custom.props')"
  Project="Custom.props"
  />

然后动态创建此属性文件,

Then dynamically create this property file, as,

<?xml version="1.0" encoding="utf-8"?>
<Project
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
  ToolsVersion="4.0">
  <PropertyGroup>
    <CustomValue>True</CustomValue>
  </PropertyGroup>
</Project>

您可以在这个.props文件中使用XmlPoke,或者使用WriteLinesToFile创建整个文件。这个辅助文件不需要被检查到源代码控制,导入条件使得项目在文件不存在时起作用。

You can either use XmlPoke on just this .props file, or use WriteLinesToFile to create the entire file. This secondary file wouldn't need to be checked into source control, the condition on the import makes the project functional when the file doesn't exist.

XmlPoke任务看起来像这样,

The XmlPoke task would look like this,

  <XmlPoke
     XmlInputPath="./Custom.props"
     Namespaces="&lt;Namespace Prefix='x'
        Uri='http://schemas.microsoft.com/developer/msbuild/2003'/&gt;"
     Query="//x:PropertyGroup/x:CustomValue/@Value"
     Value="True"
     />

这篇关于MSBuild:永久更改项目的PropertyGroup属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆