【发布时间】:2022-01-21 17:50:45
【问题描述】:
我有 2 个 csproj 项目:Child.csproj 和 Parent.csproj。 Child.csproj 通过 ProjectReference 被 Parent.csproj 引用:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Child.csproj" />
</ItemGroup>
</Project>
子项目也可以作为 x86 dll 或 x64 dll 提供。它被打包为 NuGet 包以及父项目。为了打包 2 个不同版本的子 dll,使用了下一个道具和目标文件:
Child.props
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Reference Include="Child" Condition="'$(Platform)' == 'x86'">
<HintPath>$(MSBuildThisFileDirectory)..\lib\x86\Child.dll</HintPath>
</Reference>
<Reference Include="Child" Condition="'$(Platform)' == 'x64'">
<HintPath>$(MSBuildThisFileDirectory)..\lib\x64\Child.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
子目标
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PlatformCheck" BeforeTargets="BuildOnlySettings"
Condition="(('$(Platform)' != 'x86') AND ('$(Platform)' != 'x64'))">
<Error Text="$(MSBuildThisFileName) does not work correctly on '$(Platform)' platform. You need to specify platform (x86 or x64)." />
</Target>
</Project>
此外,子项目是使用下一个 nuspec 构建的:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Child</id>
</metadata>
<files>
<file src="bin\x64\Release\netstandard2.0\Child.dll" target="lib\x64" />
<file src="bin\x86\Release\netstandard2.0\Child.dll" target="lib\x86" />
<file src="build\Child.props" target="build" />
<file src="build\Child.targets" target="build" />
</files>
</package>
这两个项目都被打包为 NuGet 包。当我直接引用子包时,它的 dll 被复制到输出文件夹。但是,当我引用 Parent 包时,我希望 Child.dll 与 Parent.dll 一起复制到项目的输出文件夹中,该文件夹引用 Parent 但它是 (Child.dll) 未复制。
【问题讨论】:
标签: c# .net-core msbuild nuget nuget-spec