[英]ProjectReference is not copied to output as part of parent NuGet package
我有 2 個 csproj 項目:Child.csproj 和 Parent.csproj。 Child.csproj 被 Parent.csproj 通過 ProjectReference 引用:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Child.csproj" />
</ItemGroup>
</Project>
子項目也可以作為 x86 dll 或 x64 dll 提供。 它被打包為 NuGet package 以及父項目。 為了 package 使用 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>
此外,Child 項目是使用下一個 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 包。 當我直接引用 Child package 時,它的 dll 被復制到 output 文件夾中。 However, when I reference Parent package, I expect Child.dll to be copied with Parent.dll as well into output folder of the project, which references Parent but it is (Child.dll) not copied.
您還需要在 nuspec 文件https: //docs.microsoft.com/en-us/nuget/reference/nuspec#dependencies-element 中指定您的依賴項
或者,根本不要使用 nuspec 並在項目文件中的一個位置定義屬性 - 這是現在發布 NuGet 包https: //docs.microsoft.com/en-us/nuget/reference/ 的推薦方式msbuild-targets#pack-target 。 通過此設置,您的 csproj 中有一個項目引用這一事實足以將依賴項正確添加到您的 package
在構建應用程序/可執行項目之前,通常不會解決傳遞依賴關系 - 因為在那之前:沒有足夠的信息來知道要包含哪些實際的 dll。 如果您在構建庫項目(引用 Parent)時看到此問題,那么:這是正常的和預期的,並且不代表任何問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.