I've a very similar problem than described in the following question Visual Studio C# projects force a rebuild when switching from debug to release and vice-versa.
I've C# two projects and one has project reference to the other. If I build (F6) in Debug and than I build (F6) in Release. If I now switch back to Debug and build (F6) it should be up to date.
That's is actually the case. So I can see that in the bin/Debug folder the file date and the assembly version are not changing.
But if I switch on the XML documentation file for the project which has project reference to the other under Project Properties / Build / Output for both configurations (Debug and Release) then the projects gets rebuild every time I switch from Debug to Release or vice-versa.
To recreate the issue:
File
/ New Project...
Visual C#
--> Console Application
. Leave the generated code as-is.Add
-> New Project...
Visual C#
--> Class Library
. Leave the generated code as-is.ConsoleApplication1
in the solution explorer and select Add Reference...
ClassLibrary1
in Solution
-> Projects
and hit OK
.XML documentation file
for the ConsoleApplication1
under Project Properties
/ Build
/ Output
for both configurations (Debug
and Release
)Debug
configuration. It builds, as expected.Release
configuration and build again. It builds, as expected.Debug
and build again. It builds, and it shouldn't. It's already been built, right? All we did was change the target configuration selection.I'm getting the following build output:
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\12.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 ==========
If XML documentation file
is switched off I'm getting the following build output (it skips the CoreCompile as it should):
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 ==========
Is this a bug? Is there a workaround?
Visual Studio Rebuilds projects when switching from debug to release and vice-versa when option XML documentation is selected
Yes, this is a known issue for Visual Studio 2013 and Visual Studio 2015. It's just a faint shock that would not affect our build results except for the extra 0.00001 second execution time.
And this issue has been fixed in the Visual Studio 2017 version 15.6. I have test it on the latest version in Visual Studio 2017 15.8.2 (Current), it works as expected.
You can find the UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
was added to the copy task in the target CopyFilesToOutputDirectory
in the file Microsoft.Common.CurrentVersion.targets
:
<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>
If this bug affects your work, you can update your Visual Studio to the 2017.
Hope this helps.