Visual Studio Rebuilds projects when switching from debug to release and vice-versa when option XML documentation is selected

Visual Studio Rebuilds projects when switching from debug to release and vice-versa when option XML documentation is selected

我遇到的问题与以下问题中描述的非常相似 Visual Studio C# projects force a rebuild when switching from debug to release and vice-versa.

我有两个 C# 项目,一个项目引用了另一个项目。 如果我在 Debug 中构建 (F6) 而不是在 Release 中构建 (F6)。如果我现在切换回调试和构建 (F6),它应该是最新的。

其实是这样的。所以我可以看到在 bin/Debug 文件夹中文件日期和程序集版本没有改变。

但是,如果我打开项目的 XML 文档文件,该项目在两个配置(调试和发布)的项目属性/构建/输出下有另一个项目引用,那么项目每次都会重建我从调试切换到发布,反之亦然。

重现问题:

  1. 点击File/New Project...
  2. 新建 Visual C# --> Console Application。保持生成的代码不变。
  3. 右键单击解决方案资源管理器中的新解决方案,然后 select Add -> New Project...
  4. 选择 Visual C# --> Class Library。保持生成的代码不变。
  5. 右键单击解决方案资源管理器中的 ConsoleApplication1 和 select Add Reference...
  6. 选中 SolutionClassLibrary1 旁边的复选框 -> Projects 并点击 OK
  7. 在项目 Properties / Build / Output 下为 ConsoleApplication1 打开 XML documentation file 两个配置(DebugRelease)
  8. Debug 配置中构建项目。它按预期构建。
  9. 切换到 Release 配置并重新构建。它按预期构建。
  10. 切换回 Debug 并重新构建。它 构建 ,但它不应该。已经建好了吧?我们所做的只是更改目标配置 selection.

我得到以下构建输出:

1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Any CPU ------
1>Build started 07.09.2018 13:46:43.
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>CoreCompile:
1>  C:\Program Files (x86)\MSBuild.0\bin\Csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /platform:anycpu32bitpreferred /errorreport:prompt /warn:4 /doc:bin\Debug\ConsoleApplication1.XML /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:H:\CSharp\TestRebuild\ClassLibrary1\bin\Debug\ClassLibrary1.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\ConsoleApplication1.exe /subsystemversion:6.00 /target:exe /utf8output Program.cs Properties\AssemblyInfo.cs "C:\Users\WO\AppData\Local\Temp\.NETFramework,Version=v4.5.AssemblyAttributes.cs" obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
1>_CopyAppConfigFile:
1>Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
1>CopyFilesToOutputDirectory:
1>  Copying file from "obj\Debug\ConsoleApplication1.exe" to "bin\Debug\ConsoleApplication1.exe".
1>  ConsoleApplication1 -> H:\CSharp\TestRebuild\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.41
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

如果 XML documentation file 关闭,我将得到以下构建输出(它应该跳过 CoreCompile):

1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Any CPU ------
1>Build started 07.09.2018 13:50:17.
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>CoreCompile:
1>Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
1>_CopyAppConfigFile:
1>Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
1>CopyFilesToOutputDirectory:
1>  ConsoleApplication1 -> H:\CSharp\TestRebuild\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.07
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

这是一个错误吗?有解决方法吗?

Visual Studio Rebuilds projects when switching from debug to release and vice-versa when option XML documentation is selected

是的,这是 Visual Studio 2013 和 Visual Studio 2015 的 known issue。这只是一个微弱的冲击,不会影响我们的构建结果,除了额外的 0.00001 秒执行时间.

并且此问题已在 Visual Studio 2017 版本 15.6 中修复。我已经在 Visual Studio 2017 15.8.2 (Current) 的最新版本上对其进行了测试,它按预期工作。

您可以在文件 Microsoft.Common.CurrentVersion.targets:

中找到 UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)" 已添加到目标 CopyFilesToOutputDirectory 中的复制任务
<Copy
    SourceFiles="@(IntermediateAssembly)"
    DestinationFolder="$(OutDir)"
    SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
    OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
    Retries="$(CopyRetryCount)"
    RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
    UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
    UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
    Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'"
        >

  <Output TaskParameter="DestinationFiles" ItemName="MainAssembly"/>
  <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>

</Copy>

如果此错误影响您的工作,您可以将 Visual Studio 更新到 2017。

希望这对您有所帮助。