导入目标文件以扩展VS2017中的构建目标

时间:2017-11-09 16:15:49

标签: visual-studio msbuild visual-studio-2017 msbuild-task

我正在尝试使用 VS2017 扩展构建功能。我在</Project>标记之前添加了以下代码到proj文件的底部:

  <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>

然后还将导入添加到proj文件中:

然后我构建项目 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 Studio\2017\Professional\MSBuild\15.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 Studio\2017\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 Studio\2017\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".

1 个答案:

答案 0 :(得分:2)

请注意,VS 2017中的经典项目系统即使在更改时也不会在构建期间重新加载导入的文件。您至少需要关闭并重新打开解决方案才能使其正常运行。

对于VS 2017 15.3+中的“SDK样式”项目(.NET标准/核心,ASP.NET核心),这由新项目系统(GitHub issue)处理。