强制项目引用包含在 netstandard nuget 包中 [英] Force project references to be included in netstandard nuget package

查看:35
本文介绍了强制项目引用包含在 netstandard nuget 包中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 netstandard 项目,其中包含两个项目参考.Visual Studio 2017 用于构建 nukpg.构建项目时,生成的 nupkg 仅包含该项目生成的程序集,并将两个项目引用列为 nuget 依赖项.有没有办法强制打包将这些程序集包含为 lib 文件?

I have a netstandard project which includes two project references. Visual studio 2017 is being used to build the nukpg. When the project is built the produced nupkg only contains the assembly produced by that project and lists the two project references as nuget dependencies. Is there a way to force the packaging to include those assemblies as lib files?

csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <RootNamespace>Verifier.Observations.DevOps.Health</RootNamespace>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <VersionPrefix>1.0.1</VersionPrefix>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..Verifier.Observations.AspectsVerifier.Observations.Aspects.csproj" />
    <ProjectReference Include="..Verifier.ObservationsVerifier.Observations.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="System.ComponentModel.Composition"/>
    <Reference Include="System.Net.Http" />
  </ItemGroup>

</Project>

更新根据@alexgiondea-msft 的反馈,现在可以使用以下内容根据需要创建包

Update Based upon feedback from @alexgiondea-msft the package is now created as desired using the following

csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <VersionPrefix>1.0.1</VersionPrefix>
    <TargetFramework>net462</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <NuspecFile>Verifier.Observations.DevOps.Health.Nuspec</NuspecFile>
   <NuspecProperties>version=$(VersionPrefix);id=$(MSBuildProjectName);author=$(Authors);copy=$(Copyright);iconUrl=$(PackageIconUrl)</NuspecProperties>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..Verifier.Observations.AspectsVerifier.Observations.Aspects.csproj" />
    <ProjectReference Include="..Verifier.ObservationsVerifier.Observations.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System.ComponentModel.Composition" />
    <Reference Include="System.Net.Http" />
  </ItemGroup>
</Project>

nuspec

<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <iconUrl>$iconUrl$</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Inspect automation service to ensure it is up and operational</description>
    <releaseNotes></releaseNotes>
    <copyright>$copy$</copyright>
    <tags>verifier-observation-plugin automation</tags>
    <dependencies>
      <group targetFramework="net462" />
    </dependencies>
    <references>
      <group targetFramework="net462">
        <reference file="Verifier.Observations.DevOps.Automation.dll" />
      </group>
    </references>
  </metadata>
  <files>
    <file src="bin*
et462*.dll" target="lib
et462" />
    <file src="bin*
et462*.pdb" target="lib
et462" />
  </files>
</package>

推荐答案

您可以使用项组中的项控制程序集在 nuget 包中的部署位置,类似于:

You can control where assemblies are deployed in the nuget package using an item in an itemgroup, similar to this:

<ItemGroup>
    <None Include="!!path_to_assembly!!">
        <PackagePath>lib
et462</PackagePath>
        <Pack>true</Pack>
        <Visible>false</Visible>
    </None>
</ItemGroup>

应该在包中包含指定的程序集.

That should include the specified assembly in the package.

这篇关于强制项目引用包含在 netstandard nuget 包中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆