使用 WriteCodeFragment MSBuild 任务

发布于 2024-10-05 06:21:44 字数 153 浏览 14 评论 0原文

我正在尝试使用 WriteCodeFragment MSBuild 任务来创建 AssemblyVersion 属性。我在创建属性组以正确传递处理所需的 ITaskItem 数组时遇到问题。有人可以帮忙举个例子吗?

I am trying to use the WriteCodeFragment MSBuild task to create an AssemblyVersion attribute. I'm having a problem creating a property group to correctly pass the ITaskItem array required for processing. Can someone help with an example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱人如己 2024-10-12 06:22:09

这将创建一个名为 BuildVersion.cs 的文件,其 AssemblyVersion 属性为 123.123.123.123。如果 OutputFile 被删除,则将使用随机生成的文件名。 Compile 项名称会自动将该项添加到 Compile 项中(在构建中包含 BuildVersion.cs)。 FileWrites 项名称允许在清理期间删除文件。

<Target Name="BeforeBuild">
  <ItemGroup>
     <AssemblyAttributes Include="AssemblyVersion">
       <_Parameter1>123.123.123.123</_Parameter1>
     </AssemblyAttributes>
  </ItemGroup>
  <WriteCodeFragment AssemblyAttributes="@(AssemblyAttributes)"
                     Language="C#"
                     OutputDirectory="$(IntermediateOutputPath)"
                     OutputFile="BuildVersion.cs">
    <Output TaskParameter="OutputFile" ItemName="Compile" />
    <Output TaskParameter="OutputFile" ItemName="FileWrites" />
  </WriteCodeFragment>
</Target>

This creates a file called BuildVersion.cs with an AssemblyVersion attribute of 123.123.123.123. If OutputFile is removed then a randomly generated file name will be used instead. The Compile item name automatically adds the item to the Compile items (includes BuildVersion.cs in the build). The FileWrites item name allows the file to be removed during Clean.

<Target Name="BeforeBuild">
  <ItemGroup>
     <AssemblyAttributes Include="AssemblyVersion">
       <_Parameter1>123.123.123.123</_Parameter1>
     </AssemblyAttributes>
  </ItemGroup>
  <WriteCodeFragment AssemblyAttributes="@(AssemblyAttributes)"
                     Language="C#"
                     OutputDirectory="$(IntermediateOutputPath)"
                     OutputFile="BuildVersion.cs">
    <Output TaskParameter="OutputFile" ItemName="Compile" />
    <Output TaskParameter="OutputFile" ItemName="FileWrites" />
  </WriteCodeFragment>
</Target>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文