2

When I set the property <DocumentationFile> on a MSBuild project, the CoreCompile task is always executed, even when all files are present and up-to-date.

MSBuild says it runs the CoreCompile task because th file "C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\bin\Debug\Test.XML" does not exist, but it exists and is up-to-date.

Details below.

My MsBuild file

I created a brand new Console Application project in Visual studio 2010, and added the following lines to the .csproj (just before the import of $(MSBuildToolsPath)\Microsoft.CSharp.targets near the end of the file):

  <PropertyGroup>
    <TargetsTriggeredByCompilation>
      $(TargetsTriggeredByCompilation);MyTarget
    </TargetsTriggeredByCompilation>
    <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
    <DocumentationFile>$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).XML</DocumentationFile>
  </PropertyGroup>
  <Target Name="MyTarget">
    <Message Text="MyTarget was executed." />
  </Target>

The reason for using UseHostCompilerIfAvailable is explained here.

The aim is to run MyTarget only when the target CoreCompile runs.

MSBuild output

When compiling with F6, and MSBuild verbosity set to Diagnostic in Tools->Options->Projects and solutions->Build and run, I get the following output:

Without <DocumentationFile>

If I remove the line

<DocumentationFile>$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).XML</DocumentationFile>

Then the CoreCompile target is ignored, which is correct:

Cible "CoreCompile : (IdCible:35)" dans le fichier "c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets" du projet "C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\Test.csproj" (la cible "Compile" en dépend) :
La cible est ignorée "CoreCompile", car tous les fichiers de sortie sont à jour par rapport aux fichiers d'entrée.
Fichiers d'entrée : Program.cs;Properties\AssemblyInfo.cs;C:\Users\Georges\AppData\Local\Temp\.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.cs;C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\Microsoft.CSharp.dll;C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll;C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll;C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.DataSetExtensions.dll;C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.dll;C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll;C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.dll;C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.Linq.dll;c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets;c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.NETFramework.props;C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\Test.csproj;c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets;c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.NETFramework.targets;c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Xaml.targets
Fichiers de sortie : obj\x86\Debug\Test.exe;obj\x86\Debug\Test.pdb
Génération de la cible "CoreCompile" terminée dans le projet "Test.csproj". : (IdCible:35)

With <DocumentationFile>

If I keep the line

<DocumentationFile>$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).XML</DocumentationFile>

Then the CoreCompile target is run, which is inccorrect.

MSBuild says it is run because the output file "C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\bin\Debug\Test.XML" does not exist, but I'm 100% positive that it indeed does exist (copying-pasting the path verbatim into Notepad++'s open dialog indeed opens the file).

I tried setting the <DocumentationFile> property to:

  • $(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).XML
  • $(MSBuildProjectDirectory)\$(OutputPath)\$(MSBuildProjectName).XML
  • $(OutputPath)\$(MSBuildProjectName).XML
  • $(OutputPath)$(MSBuildProjectName).XML
  • bin\Debug\Test.XML
  • Setting the default value (bin\Debug\Test.XML) through the project's properties in the Build tab.

But it doesn't change anything, the CoreCompile target is still run.

Cible "CoreCompile : (IdCible:35)" dans le fichier "c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets" du projet "C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\Test.csproj" (la cible "Compile" en dépend) :
Génération complète de la cible "CoreCompile".
Le fichier de sortie "C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\bin\Debug\Test.XML" n'existe pas.
Tâche "Csc" (IDTâche:13)
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /doc:"C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\bin\Debug\Test.XML" /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\Microsoft.CSharp.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\x86\Debug\Test.exe /target:exe /utf8output Program.cs Properties\AssemblyInfo.cs "C:\Users\Georges\AppData\Local\Temp\.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.cs" (IDTâche:13)
  Compilateur Microsoft (R) Visual C# 2010 version 4.0.30319.1 (IDTâche:13)
  Copyright (C) Microsoft Corporation. Tous droits réservés. (IDTâche:13)
   (IDTâche:13)
Exécution de la tâche "Csc" terminée. (IDTâche:13)
Tâche "CallTarget" (IDTâche:14)
Cible "MyTarget : (IdCible:36)" du projet "C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\Test.csproj" (la cible "CoreCompile" en dépend) :
Tâche "Message" (IDTâche:15)
  MyTarget was executed. (IDTâche:15)
Exécution de la tâche "Message" terminée. (IDTâche:15)
Génération de la cible "MyTarget" terminée dans le projet "Test.csproj". : (IdCible:36)
Exécution de la tâche "CallTarget" terminée. (IDTâche:14)
Génération de la cible "CoreCompile" terminée dans le projet "Test.csproj". : (IdCible:35)
Suzanne Soy
  • 3,027
  • 6
  • 38
  • 56
  • 1
    Try to use Process Monitor to see what exactly happens when that path is being accessed. That might show you what's up. – Lex Li Apr 25 '13 at 09:43
  • @LexLi Indeed, Process Monitor showed that the file is renamed to a temporary name, so this is probably the cause. Now I'll go search where in Microsoft's `.target`s does this file gets renamed. – Suzanne Soy Apr 25 '13 at 10:22
  • Please update post with English output from msbuild, so that in can be googled at least. – Lanorkin Apr 26 '13 at 12:43
  • Target will be skipped, if `outputs` modification date is newer than `inputs`, so just file **existence** is not enough. Is it the case? – Lanorkin Apr 26 '13 at 12:44
  • @Lanorkin: Sorry but one can't change Visual Studio's language (I have already tried, trust me, having badly translated french error messages doesn't make my job easy). For your second question, yes, the file is more recent than the inputs, but MSBuild specifically says it doesn't exist. Thanks to Lex Li's insight, I found that the file seems to be renamed (and then deleted) during MSBuild's execution. I tried to find where this is done in Microsoft's MSBuild files, and it seams there is something related to incremental cleaning, and this file is added to the list. That's my best guess so far. – Suzanne Soy Apr 26 '13 at 15:35

0 Answers0