预构建 MSBuild 任务以更新与构建的 exe 不同步的 AssemblyInfo

Pre-build MSBuild task to update AssemblyInfo not in sync with built exe(预构建 MSBuild 任务以更新与构建的 exe 不同步的 AssemblyInfo)
本文介绍了预构建 MSBuild 任务以更新与构建的 exe 不同步的 AssemblyInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 Visual Studio 2008 中使用调用 msbuild 的预构建任务:

I am using a pre-build task in Visual Studio 2008 that invokes msbuild:

C:WINDOWSMicrosoft.NETFrameworkv3.5MSBuild.exe $(MSBuildProjectDirectory)version.targets /p:Configuration=$(ConfigurationName)

在 version.targets 中,我正在更新 AssemblyInfo.cs 文件以替换版本信息:

Inside version.targets, I am updating the AssemblyInfo.cs file to replace version information:

   <FileUpdate
        Encoding="ASCII"
        Files="$(MSBuildProjectDirectory)PropertiesAssemblyInfo.cs"
        Regex="AssemblyInformationalVersion(&quot;.*&quot;)]" 
        ReplacementText="AssemblyInformationalVersion(&quot;Product $(ConfigurationString) ($(buildDate))&quot;)]"
    />

当我通过 Visual Studio 2008 构建项目时,它构建没有任何问题.

When I build the project through Visual Studio 2008, it builds without any problems.

但是当我查看生成的 exe 的版本信息时,它包含以前的时间戳,即使 AssemblyInfo.cs 已更改为正确"的时间戳.

But when I look at the resulting exe's version information, it contains the previous time stamp even though the AssemblyInfo.cs has been changed with the "correct" one.

主编译任务似乎看不到预构建的更改,并且总是落后.

It seems that the pre-build's changes aren't seen by the main compilation task and it's always one behind.

对我做错了什么有任何想法吗?

Any ideas of what I'm doing wrong?

推荐答案

我不认为你做错了什么 - 这是一个错误.

I don't think you are doing anything wrong - it's a bug.

我已经报告了它这里 - 检查你是否可以重现它并添加验证,也许我们可以通过 MS 修复它.

I have reported it here - check if you can reproduce it and add a validation, maybe we can get it fixed by MS.

我尝试了Si"的建议来更新BeforeBuild"事件中的文件 - 但是我仍然得到与 Visual Studio 2008/SP1 相同的错误结果.

I tried the suggestion by "Si" to update the file in the "BeforeBuild" event - however I still get the same wrong result with Visual Studio 2008/SP1.

更新/解决方法:MS 已回复错误报告.作为一种解决方法,您可以添加

UPDATE/WORKAROUND: MS has responded to the bug report. As a workaround you can add

<UseHostCompilerIfAvailable>FALSE</UseHostCompilerIfAvailable>

到您的 csproj 文件.

to your csproj file.

这篇关于预构建 MSBuild 任务以更新与构建的 exe 不同步的 AssemblyInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

MSBuild cannot find a reference(MSBuild 找不到参考)
The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)