Visual studio 使用模块化Visual Studio项目文件有困难

Visual studio 使用模块化Visual Studio项目文件有困难,visual-studio,visual-studio-2008,msbuild,Visual Studio,Visual Studio 2008,Msbuild,我正在尝试模块化VisualStudio项目文件,但它不起作用。这是针对VisualStudio2008和.NET3.5的 如下图所示,第一个示例有效,但第二个示例无效。我怎样才能使它工作 我对这个话题不熟悉,可能遗漏了什么。我最初是在阅读第三方时意识到这一点的,然后又在第三方中发现了它。我在谷歌上搜索了更多的帮助,但是有太多的信息让我无法找到相关的答案 主项目文件: ... <!-- main project file --> <Import Project="$

我正在尝试模块化VisualStudio项目文件,但它不起作用。这是针对VisualStudio2008和.NET3.5的

如下图所示,第一个示例有效,但第二个示例无效。我怎样才能使它工作

我对这个话题不熟悉,可能遗漏了什么。我最初是在阅读第三方时意识到这一点的,然后又在第三方中发现了它。我在谷歌上搜索了更多的帮助,但是有太多的信息让我无法找到相关的答案

主项目文件:

  ...
  <!-- main project file -->
  <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />

  <Target Name="AfterBuild">
    <Message Text="This is a message from the *.vbproj file."/> ... this works
  </Target>
</Project>
  ...
  <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
  <Import Project="$(MSBuildProjectDirectory)\CustomBuildEvents.targets" /> ... new tag

  <Target Name="AfterBuild">
    <Message Text="This is a message from the *.vbproj file."/> ... this still works
  </Target>
</Project>
后构建的问题是它只能定义一次。因此,如果导入它,然后稍后在项目文件中再次定义它,最后一个定义将获胜并成为唯一的定义

要解决这个问题,您需要使用更高级的方法来注册事件。既然您使用的是Visual Studio 2008,为什么?!,您需要对自定义目标文件使用更高级的语法:

<Project>
    <!-- 
        Redefines the original build order, includes the standard targets and 
        adds your new custom target to the end of the list.
    -->
    <PropertyGroup>
        <BuildDependsOn>
            $(BuildDependsOn);
            CustomTarget
        </BuildDependsOn>
    </PropertyGroup>

    <CustomTarget> 
        <!-- Imported after Build -->
        <Message Text="Hello from the imported file." Importance ="high"/>
    </CustomTarget>
</Project>
MsBuild 4中还引入了其他方法,在任何目标上都有BeforeTargets和AfterTargets属性,但如果我没记错的话,上述语法也应该适用于Visual Studio 2008附带的MsBuild版本

另见:


是的,我刚刚在别处读到了唯一一次的问题,并意识到它的重要性。我使用2008是因为它在工作中是多余的,我免费得到它,还有许可证等等。关于你的链接,我已经读了第一篇,有点…现在我有点不知所措。但第二次很有帮助,在你的帮助下,我度过了难关。这钻头起作用了。尽管XML解析器一直对我打喷嚏,直到我把它包起来。在这个过程中,我确实想知道目标名称是否是一个问题。谢谢你的帮助+1现在…关于注册表任务,哈哈。Visual Studio 2019社区版是免费供个人使用的,即使您使用它构建商业软件。缺少什么=-这基本上与Pro相同,这是限制:不适用于企业组织,定义为>250台电脑或>100万美元的年收入。哇,我正在尽我最大的努力。似乎在某个地方一定有一个陷阱,比如微软拥有你用它制作的代码,就像Facebook拥有你上传的任何照片。我对此表示怀疑=-
### Halfway through the output, this is the only mention of the imported file. ###

None
    CustomBuildEvents.targets      ... custom file
    My Project\Application.myapp
    My Project\Settings.settings

### And then at the end, no mention of the imported file or its message. ###

Done building target "CoreBuild" in project "MsBuildCustomTargetTester.vbproj".
Target "AfterBuild" in file "C:\Visual Studio 2008\Solutions\MsBuildCustomTargetTester\MsBuildCustomTargetTester\MsBuildCustomTargetTester.vbproj":
  Task "Message"
    Hello from the *.vbproj file.      ... message from main file
  Done executing task "Message".
Done building target "AfterBuild" in project "MsBuildCustomTargetTester.vbproj".
Target "Build" in file "c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets":
  Building target "Build" completely.
  No input files were specified.
Done building target "Build" in project "MsBuildCustomTargetTester.vbproj".

Done building project "MsBuildCustomTargetTester.vbproj".

Project Performance Summary:
      109 ms  C:\Visual Studio 2008\Solutions\MsBuildCustomTargetTester\MsBuildCustomTargetTester\MsBuildCustomTargetTester.vbproj   1 calls
<Project>
    <!-- 
        Redefines the original build order, includes the standard targets and 
        adds your new custom target to the end of the list.
    -->
    <PropertyGroup>
        <BuildDependsOn>
            $(BuildDependsOn);
            CustomTarget
        </BuildDependsOn>
    </PropertyGroup>

    <CustomTarget> 
        <!-- Imported after Build -->
        <Message Text="Hello from the imported file." Importance ="high"/>
    </CustomTarget>
</Project>