导入目标文件以扩展 VS2017 中的构建目标
Import targets file to extend build targets in VS2017
我正在尝试使用 VS2017 扩展构建功能。我已将以下代码添加到 proj 文件的底部,就在 </Project>
标记之前:
<Target Name="PrintA" BeforeTargets="Build">
<Message Text="AAAAAAAAAAAAAa" Importance="high" />
</Target>
按预期工作。现在我想创建单独的目标文件 - build.targets 并在那里添加构建逻辑。因此,我使用以下代码在解决方案根文件夹中创建了 build.targets 文件:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PrintB" BeforeTargets="Build">
<Message Text="BBBBBBBBBBBBBBBBBBBBB" Importance="high"/>
</Target>
</Project>
然后也将导入添加到项目文件中:
然后我构建项目,打印 AAAAAA 而 BBBBB 没有。我想念什么?
更新:这是构建日志(我无法粘贴完整日志,我认为只有此信息相关):
Task "WriteLinesToFile" skipped, due to false condition; ('@(_CleanUnfilteredPriorFileWrites)'!='@(_CleanUniqueRemainingFileWritesAfterIncrementalClean)') was evaluated as ('C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dacpac;C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dll;C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.pdb;C:\Users\kultasev\source\repos\Database2\Database2\obj\Debug\Database2.dll;C:\Users\kultasev\source\repos\Database2\Database2\obj\Debug\Database2.pdb'!='C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dacpac;C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dll;C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.pdb;C:\Users\kultasev\source\repos\Database2\Database2\obj\Debug\Database2.dll;C:\Users\kultasev\source\repos\Database2\Database2\obj\Debug\Database2.pdb').
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '' and ('$(RunPostBuildEvent)' != 'OnOutputUpdated' or '$(_AssemblyTimestampBeforeCompile)' != '$(_AssemblyTimestampAfterCompile)')) was evaluated as ('' != '' and ('' != 'OnOutputUpdated' or '' != '')).
Target "AfterBuild" in file "C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets" from project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (target "Build" depends on it):
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "PrintA" in project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (target "Build" depends on it):
Task "Message"
Task Parameter:Text=AAAAAAAAAAAAAa
Task Parameter:Importance=high
AAAAAAAAAAAAAa
Target "PrintB" in file "C:\Users\kultasev\source\repos\Database2\Database2\build.targets" from project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (target "Build" depends on it):
Task "Message"
Task Parameter:Text=BBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBB
Target "Build" in file "C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" from project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (entry point):
Task "CallTarget" skipped, due to false condition; ('$(UnloadProjectsOnCompletion)'=='true') was evaluated as (''=='true').
Task "CallTarget" skipped, due to false condition; ('$(UnloadProjectsOnCompletion)'=='true') was evaluated as (''=='true').
Task "CallTarget" skipped, due to false condition; ('$(UnloadProjectsOnCompletion)'=='true') was evaluated as (''=='true').
Target "CleanupEmptyRefsFolder" in file "C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\Managed.Web\Microsoft.Web.IISSupport.targets" from project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (entry point):
Set Property: _RefsFolderFullPath=C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\
Added Item(s):
_FilesInRefsFolder=
C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dacpac
C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dll
C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.pdb
Task "RemoveDir" skipped, due to false condition; (@(_FilesInRefsFolder ->Count()) == 0) was evaluated as (3 == 0).
Done building project "Database2.sqlproj".
请注意,VS 2017 中的经典项目系统不会在构建期间重新加载导入的文件,即使它们发生变化。您至少需要关闭并重新打开解决方案才能使其正常工作。
对于 VS 2017 15.3+ 中的 "SDK-style" 项目(.NET Standard/Core、ASP.NET 核心),这由新项目系统 (GitHub issue) 处理。
我正在尝试使用 VS2017 扩展构建功能。我已将以下代码添加到 proj 文件的底部,就在 </Project>
标记之前:
<Target Name="PrintA" BeforeTargets="Build">
<Message Text="AAAAAAAAAAAAAa" Importance="high" />
</Target>
按预期工作。现在我想创建单独的目标文件 - build.targets 并在那里添加构建逻辑。因此,我使用以下代码在解决方案根文件夹中创建了 build.targets 文件:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PrintB" BeforeTargets="Build">
<Message Text="BBBBBBBBBBBBBBBBBBBBB" Importance="high"/>
</Target>
</Project>
然后也将导入添加到项目文件中:
然后我构建项目,打印 AAAAAA 而 BBBBB 没有。我想念什么?
更新:这是构建日志(我无法粘贴完整日志,我认为只有此信息相关):
Task "WriteLinesToFile" skipped, due to false condition; ('@(_CleanUnfilteredPriorFileWrites)'!='@(_CleanUniqueRemainingFileWritesAfterIncrementalClean)') was evaluated as ('C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dacpac;C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dll;C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.pdb;C:\Users\kultasev\source\repos\Database2\Database2\obj\Debug\Database2.dll;C:\Users\kultasev\source\repos\Database2\Database2\obj\Debug\Database2.pdb'!='C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dacpac;C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dll;C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.pdb;C:\Users\kultasev\source\repos\Database2\Database2\obj\Debug\Database2.dll;C:\Users\kultasev\source\repos\Database2\Database2\obj\Debug\Database2.pdb').
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '' and ('$(RunPostBuildEvent)' != 'OnOutputUpdated' or '$(_AssemblyTimestampBeforeCompile)' != '$(_AssemblyTimestampAfterCompile)')) was evaluated as ('' != '' and ('' != 'OnOutputUpdated' or '' != '')).
Target "AfterBuild" in file "C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets" from project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (target "Build" depends on it):
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "PrintA" in project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (target "Build" depends on it):
Task "Message"
Task Parameter:Text=AAAAAAAAAAAAAa
Task Parameter:Importance=high
AAAAAAAAAAAAAa
Target "PrintB" in file "C:\Users\kultasev\source\repos\Database2\Database2\build.targets" from project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (target "Build" depends on it):
Task "Message"
Task Parameter:Text=BBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBB
Target "Build" in file "C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" from project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (entry point):
Task "CallTarget" skipped, due to false condition; ('$(UnloadProjectsOnCompletion)'=='true') was evaluated as (''=='true').
Task "CallTarget" skipped, due to false condition; ('$(UnloadProjectsOnCompletion)'=='true') was evaluated as (''=='true').
Task "CallTarget" skipped, due to false condition; ('$(UnloadProjectsOnCompletion)'=='true') was evaluated as (''=='true').
Target "CleanupEmptyRefsFolder" in file "C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\Managed.Web\Microsoft.Web.IISSupport.targets" from project "C:\Users\kultasev\source\repos\Database2\Database2\Database2.sqlproj" (entry point):
Set Property: _RefsFolderFullPath=C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\
Added Item(s):
_FilesInRefsFolder=
C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dacpac
C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.dll
C:\Users\kultasev\source\repos\Database2\Database2\bin\Debug\Database2.pdb
Task "RemoveDir" skipped, due to false condition; (@(_FilesInRefsFolder ->Count()) == 0) was evaluated as (3 == 0).
Done building project "Database2.sqlproj".
请注意,VS 2017 中的经典项目系统不会在构建期间重新加载导入的文件,即使它们发生变化。您至少需要关闭并重新打开解决方案才能使其正常工作。
对于 VS 2017 15.3+ 中的 "SDK-style" 项目(.NET Standard/Core、ASP.NET 核心),这由新项目系统 (GitHub issue) 处理。