当我在 MSBuild 项目上设置属性
<DocumentationFile>
时,即使所有文件都存在且是最新的,CoreCompile
任务也始终会执行。
MSBuild 表示它运行
CoreCompile
任务,因为文件 "C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\bin\Debug\Test.XML"
不存在,但它存在并且是最新的。
详情如下。
我在 Visual studio 2010 中创建了一个全新的控制台应用程序项目,并将以下几行添加到
.csproj
(就在靠近文件末尾的 import
的 $(MSBuildToolsPath)\Microsoft.CSharp.targets
之前):
<PropertyGroup>
<TargetsTriggeredByCompilation>
$(TargetsTriggeredByCompilation);MyTarget
</TargetsTriggeredByCompilation>
<UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
<DocumentationFile>$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).XML</DocumentationFile>
</PropertyGroup>
<Target Name="MyTarget">
<Message Text="MyTarget was executed." />
</Target>
使用
UseHostCompilerIfAvailable
的原因已解释here。
目标是只有当目标
MyTarget
运行时才运行CoreCompile
。
使用
F6
进行编译,并将 MSBuild 详细程度设置为 Diagnostic
中的 Tools->Options->Projects and solutions->Build and run
时,我得到以下输出:
<DocumentationFile>
如果我删除线
<DocumentationFile>$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).XML</DocumentationFile>
然后 CoreCompile 目标被忽略,这是正确的:
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)
<DocumentationFile>
如果我保持线路
<DocumentationFile>$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).XML</DocumentationFile>
然后运行
CoreCompile
目标,这是不正确的。
MSBuild 说它已运行,因为输出文件
"C:\Users\Georges\Documents\Visual Studio 2010\Projects\Test\Test\bin\Debug\Test.XML"
不存在,但我 100% 肯定它确实存在(将路径逐字复制粘贴到 Notepad++ 的 open
对话框中确实会打开该文件)。
我尝试将
<DocumentationFile>
属性设置为:
$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).XML
$(MSBuildProjectDirectory)\$(OutputPath)\$(MSBuildProjectName).XML
$(OutputPath)\$(MSBuildProjectName).XML
$(OutputPath)$(MSBuildProjectName).XML
bin\Debug\Test.XML
bin\Debug\Test.XML
选项卡中的项目属性设置默认值 (Build
)。但它不会改变任何东西,
CoreCompile
目标仍然在运行。
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)
我从本期的评论中找到了解决该问题的方法: https://github.com/dotnet/project-system/issues/3069#issuecomment-354310356
该问题声称已修复,但至少对我们来说,它是在 VS 17.4.4 中发生的。
解决方案是将
<DocumentationFile>
更改为指向主输出文件夹之外。 VS 会在构建结束时自动将文档文件复制到主输出文件夹,因此它仍然可以在您期望的位置使用。由于某种原因,当文件的初始生成位置与最终目标相同时,在某些情况下会感到困惑。
Before:
<DocumentationFile>bin\Debug\My.Assembly.xml</DocumentationFile>
After:
<DocumentationFile>obj\Debug\My.Assembly.xml</DocumentationFile>