如何在 BuiltProjectOutputGroup 中包含一个项目
How to include an item in BuiltProjectOutputGroup
我有一个自定义项目系统,它使用标准的 net sdk 目标。
在构建过程中,我生成了一个额外的 zip 文件。我希望这个额外的文件包含在输出组中,这样当我查询我的项目输出组(来自 vs)时,它就会显示出来。
我的项目文件如下所示:
<Project Sdk="Microsoft.NET.Sdk">
... stuff
<ItemGroup>
<PackageReference Include="DnnVsProjectSystem.BuildTools" Version="0.0.5">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(CustomProjectExtensionsPath)DnnVsProjectSystem.targets"/>
</Project>
注意,我正在使用 "sdk" 属性,这是 msbuild 的一项相当新的功能。
您看到的 PackageReference
是一个导入 .props 和 .targets 的 nuget 包,其中 augment
使用一些自定义构建任务进行构建。这些是生成 zip 文件的文件。
我深入研究了 net sdk
个目标并发现了这个:
<Target Name="AllProjectOutputGroups" DependsOnTargets="
 BuiltProjectOutputGroup;
 DebugSymbolsProjectOutputGroup;
 DocumentationProjectOutputGroup;
 SatelliteDllsProjectOutputGroup;
 SourceFilesProjectOutputGroup;
 ContentFilesProjectOutputGroup;
 SGenFilesOutputGroup" />
<!--
This is the key output for the BuiltProjectOutputGroup and is meant to be read directly from the IDE.
Reading an item is faster than invoking a target.
-->
<ItemGroup Condition=" '$(OutputType)' != 'winmdobj' ">
<BuiltProjectOutputGroupKeyOutput Include="@(IntermediateAssembly->'%(FullPath)')">
<IsKeyOutput>true</IsKeyOutput>
<FinalOutputPath>$(TargetPath)</FinalOutputPath>
<TargetPath>$(TargetFileName)</TargetPath>
<COM2REG Condition="'$(RegisterForComInterop)'=='true' and '$(OutputType)'=='library'">true</COM2REG>
</BuiltProjectOutputGroupKeyOutput>
</ItemGroup>
<ItemGroup Condition=" '$(OutputType)' == 'winmdobj' ">
<WinMDExpOutputWindowsMetadataFileItem Include="$(_IntermediateWindowsMetadataPath)" Condition="'$(_IntermediateWindowsMetadataPath)' != ''" />
<BuiltProjectOutputGroupKeyOutput Include="@(WinMDExpOutputWindowsMetadataFileItem->'%(FullPath)')">
<IsKeyOutput>true</IsKeyOutput>
<FinalOutputPath>$(TargetPath)</FinalOutputPath>
<TargetPath>$(TargetFileName)</TargetPath>
</BuiltProjectOutputGroupKeyOutput>
</ItemGroup>
这似乎是 VS 在需要有关输出组的信息时调用的目标。
问题是,我不确定如何将我的项目包含在这些输出组之一中,因为如果我只是将项目添加到项目组,在我自己的目标中 - 我的目标与此无关点,因为它们不包含在此依赖链中。
我也无法覆盖任何目标,因为当我使用 sdk
属性时,看起来 sdk 目标总是最后导入,覆盖我声明的任何内容。
非常感谢任何指导。
如果您唯一关心的是挂接到目标或其依赖链,我建议使用 msbuild 的 BeforeTargets
功能:
<Target Name="IncludeMyCustomOutputGroup" BeforeTargets="AllProjectOutputGroups" DependsOnTargets="ResolveMyCustomPropertiesAndItems">
<ItemGroup>
<!-- Assuming @(MyCustomOutput) items are generated by your ResolveMyCustomPropertiesAndItems target, or just add anything else -->
<BuiltProjectOutputGroupKeyOutput Include="@(MyCustomOutput->'%(FullPath)')">
<IsKeyOutput>true</IsKeyOutput>
<FinalOutputPath>$(TargetPath)</FinalOutputPath>
<TargetPath>$(TargetFileName)</TargetPath>
</BuiltProjectOutputGroupKeyOutput>
</ItemGroup>
</Target>
我有一个自定义项目系统,它使用标准的 net sdk 目标。 在构建过程中,我生成了一个额外的 zip 文件。我希望这个额外的文件包含在输出组中,这样当我查询我的项目输出组(来自 vs)时,它就会显示出来。
我的项目文件如下所示:
<Project Sdk="Microsoft.NET.Sdk">
... stuff
<ItemGroup>
<PackageReference Include="DnnVsProjectSystem.BuildTools" Version="0.0.5">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(CustomProjectExtensionsPath)DnnVsProjectSystem.targets"/>
</Project>
注意,我正在使用 "sdk" 属性,这是 msbuild 的一项相当新的功能。
您看到的 PackageReference
是一个导入 .props 和 .targets 的 nuget 包,其中 augment
使用一些自定义构建任务进行构建。这些是生成 zip 文件的文件。
我深入研究了 net sdk
个目标并发现了这个:
<Target Name="AllProjectOutputGroups" DependsOnTargets="
 BuiltProjectOutputGroup;
 DebugSymbolsProjectOutputGroup;
 DocumentationProjectOutputGroup;
 SatelliteDllsProjectOutputGroup;
 SourceFilesProjectOutputGroup;
 ContentFilesProjectOutputGroup;
 SGenFilesOutputGroup" />
<!--
This is the key output for the BuiltProjectOutputGroup and is meant to be read directly from the IDE.
Reading an item is faster than invoking a target.
-->
<ItemGroup Condition=" '$(OutputType)' != 'winmdobj' ">
<BuiltProjectOutputGroupKeyOutput Include="@(IntermediateAssembly->'%(FullPath)')">
<IsKeyOutput>true</IsKeyOutput>
<FinalOutputPath>$(TargetPath)</FinalOutputPath>
<TargetPath>$(TargetFileName)</TargetPath>
<COM2REG Condition="'$(RegisterForComInterop)'=='true' and '$(OutputType)'=='library'">true</COM2REG>
</BuiltProjectOutputGroupKeyOutput>
</ItemGroup>
<ItemGroup Condition=" '$(OutputType)' == 'winmdobj' ">
<WinMDExpOutputWindowsMetadataFileItem Include="$(_IntermediateWindowsMetadataPath)" Condition="'$(_IntermediateWindowsMetadataPath)' != ''" />
<BuiltProjectOutputGroupKeyOutput Include="@(WinMDExpOutputWindowsMetadataFileItem->'%(FullPath)')">
<IsKeyOutput>true</IsKeyOutput>
<FinalOutputPath>$(TargetPath)</FinalOutputPath>
<TargetPath>$(TargetFileName)</TargetPath>
</BuiltProjectOutputGroupKeyOutput>
</ItemGroup>
这似乎是 VS 在需要有关输出组的信息时调用的目标。
问题是,我不确定如何将我的项目包含在这些输出组之一中,因为如果我只是将项目添加到项目组,在我自己的目标中 - 我的目标与此无关点,因为它们不包含在此依赖链中。
我也无法覆盖任何目标,因为当我使用 sdk
属性时,看起来 sdk 目标总是最后导入,覆盖我声明的任何内容。
非常感谢任何指导。
如果您唯一关心的是挂接到目标或其依赖链,我建议使用 msbuild 的 BeforeTargets
功能:
<Target Name="IncludeMyCustomOutputGroup" BeforeTargets="AllProjectOutputGroups" DependsOnTargets="ResolveMyCustomPropertiesAndItems">
<ItemGroup>
<!-- Assuming @(MyCustomOutput) items are generated by your ResolveMyCustomPropertiesAndItems target, or just add anything else -->
<BuiltProjectOutputGroupKeyOutput Include="@(MyCustomOutput->'%(FullPath)')">
<IsKeyOutput>true</IsKeyOutput>
<FinalOutputPath>$(TargetPath)</FinalOutputPath>
<TargetPath>$(TargetFileName)</TargetPath>
</BuiltProjectOutputGroupKeyOutput>
</ItemGroup>
</Target>