繁体   English   中英

ProjectReference 未作为父 NuGet package 的一部分复制到 output

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM