简体   繁体   English

Visual Studio(2010)内部版本与MSBuild从命令行的不同行为

[英]Different behavior of Visual Studio (2010) build vs MSBuild from command line

I am trying to customize my solution with a custom MSBuild target, which modifies AssemblyVersion and AssemblyFileVersion assembly attributes and puts either build number from CI or just increments the current value of one if we are building on the local machine. 我正在尝试使用自定义MSBuild目标来自定义我的解决方案,该目标将修改AssemblyVersionAssemblyFileVersion程序集属性,并从CI放入内部版本号,或者如果我们在本地计算机上进行构建,则仅增加当前值之一。 I have placed that custom target as a dependency for the BeforeBuild standard target so it should be executing before every build: 我已将该自定义目标放置为BeforeBuild标准目标的依赖项,因此它应在每次构建之前执行:

  <Target Name="BeforeBuild" DependsOnTargets="VersionTag" />

And I am experiencing the following issue. 我正在遇到以下问题。 When I am building from the command line, things are good, and AssemblyInfo.cs files are being modified before build, and new version numbers come to newly built assemblies. 当我从命令行进行构建时,一切都很好,并且在构建之前会修改AssemblyInfo.cs文件,并且新版本号会出现在新建的程序集中。

But when I am building from within the Visual Studio, assemblies are getting the old version numbers, and AssemblyInfo.cs files are being modified after the actual build. 但是,当我从Visual Studio中进行构建时,程序集获取的是旧版本号,并且在实际构建之后会修改AssemblyInfo.cs文件。 The Output window shows something like this - please note that compilation warnings and "Compile complete" message are being shown before the "Build started" message: “输出”窗口显示如下内容-请注意,在“开始构建”消息之前会显示编译警告和“编译完成”消息:

------ Rebuild All started: Project: CommonModel, Configuration: Debug Any CPU ------
C:\Applications\Domain\CommonModel\History\CommonHistory.cs(7,42): warning CS0108: 'Domain.CommonModel.History.CommonHistory.Parent' hides inherited member 'Domain.CommonModel.Common.Parent'. Use the new keyword if hiding was intended.
C:\Applications\Domain\CommonModel\Common.cs(36,35): (Related location)

Compile complete -- 0 errors, 14 warnings
Build started 6/5/2014 6:40:00 PM.
CoreClean:
  Deleting file "C:\Applications\Domain\CommonModel\bin\Debug\Domain.CommonModel.dll.config".
  Deleting file "C:\Applications\Domain\CommonModel\bin\Debug\Domain.CommonModel.dll".
  Deleting file "C:\Applications\Domain\CommonModel\bin\Debug\Domain.CommonModel.pdb".

. . .

Knowing that VS uses MSBuild at the background I was expecting the same behavior for both kinds of builds, at least with the sequence of core events. 知道VS在后台使用MSBuild时,我期望两种构建都具有相同的行为,至少在核心事件序列方面。 So now I am slightly confused if there is a chance to bring VS and command line build into consistence. 因此,如果有机会使VS和命令行构建保持一致,那么现在我有些困惑。

There are many differences between MSBuild and VS. MSBuild和VS之间有很多区别。 For one, many .targets files, including ones that come with .NET/VS, have stuff with Condition="'$(BuildingInsideVisualStudio)' == 'true'" . 例如,许多.target文件,包括.NET / VS随附的文件,都带有Condition="'$(BuildingInsideVisualStudio)' == 'true'" Also, VS takes many shortcuts in generating the dependency tree of the solution. 此外,VS在生成解决方案的依赖关系树时采取了许多捷径。

As for your issue: I dislike the practice of overriding targets like BeforeBuild . 至于您的问题:我不喜欢覆盖诸如BeforeBuild目标的做法。 What if 2 people did this? 如果有2个人这样做,该怎么办? The latter would overwrite the former. 后者将覆盖前者。 Instead, use MSBuild 3 and later's BeforeTargets feature - in your case, you'd just have your target as: 而是使用MSBuild 3和更高版本的BeforeTargets功能-在您的情况下,您只需将目标设置为:

<Target Name="VersionTag" BeforeTargets="BeforeBuild">(...)

...And maybe that would fix your issue as well. ...也许这也可以解决您的问题。

If not, you could increase MSBuild logging level (Tools=>Options=>Projects and Solutions => Build and Run), and then the log will tell you more. 如果不是,则可以提高MSBuild日志记录级别(工具=>选项=>项目和解决方案=>生成并运行),然后该日志将告诉您更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio生成解决方案,但命令行中的MSBuild失败 - Visual Studio builds solution but MSBuild from the command line fails 命令行生成解决方案与Visual Studio 2012生成 - Command line build solution vs Visual Studio 2012 build Visual Studio用于通过msbuild命令行进行增量生成的生成目标 - Build target used by Visual Studio to do Incremental Build via msbuild command line 使用Visual Studio 2010从命令行构建C#解决方案 - Building C# solutions from command line with Visual Studio 2010 msbuild在命令行上工作,但VS2010表示项目“未选中” - msbuild works on command line but VS2010 says a project is “not selected” MSBuild从命令行失败,但从Visual Studio cmd行成功 - MSBuild fails from command Line but succeeds from visual studio cmd line 使用 MSBuild 构建 ASP.Net 网站与 Visual Studio 构建不同 - Build ASP.Net Website with MSBuild is different from Visual Studio build 在Visual Studio 2010中构建的不同项目集 - Different sets of projects to build in Visual Studio 2010 为什么我在 Visual Studio 2019 Output 与管理员开发 cmd 提示之间得到不同的 MSBuild 行为 - Why am I getting different MSBuild behavior between Visual Studio 2019 Output vs admin dev cmd prompt 从命令行在2017 Visual Studio中构建项目? - Build project in 2017 Visual Studio from the command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM