简体   繁体   English

为多个 SDK 项目创建 nuget 包

[英]Create nuget package for multiple SDK projects

I have 3 .net standard SDK projects( Utils , Reporting and Testing ) that I want to pack them into one nuget package called Shared and upload it in my local package management system to be able to be used in my other projects.我有 3 个 .net 标准 SDK 项目( UtilsReportingTesting ),我想将它们打包到一个名为Shared的 nuget 包中,并将其上传到我的本地包管理系统中,以便能够在我的其他项目中使用。 I was thinking to use the csproj file(s) to fill all the package information so I don't have to use nuspec file(s).我正在考虑使用csproj文件来填充所有包信息,因此我不必使用nuspec文件。 One way I tried is to create a new .net standard project called Shared that references all the first 3 projects and only fill the Shared.csproj .我尝试的一种方法是创建一个名为Shared的新 .net 标准项目,它引用所有前 3 个项目,并且只填充Shared.csproj

<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
     <Copyright>Copyright (c) Me</Copyright>
     <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
     <SkipCopyBuildProduct>true</SkipCopyBuildProduct>
     <GenerateDependencyFile>False</GenerateDependencyFile>
     <DebugSymbols>false</DebugSymbols>
     <DebugType>none</DebugType>
   </PropertyGroup>
   <ItemGroup>
     <ProjectReference Include="..\Utils.csproj" />
     <ProjectReference Include="..\Reporting.csproj" />
     <ProjectReference Include="..\Testing.csproj" />
   </ItemGroup>
</Project>

I've tried this msbuild command:我试过这个 msbuild 命令:

dotnet msbuild -t:pack=Shared.csproj;-p:Configuration=Release;PackageOutputPath=.\release;

and this nuget cli command:和这个 nuget cli 命令:

nuget pack Shared.csproj -Build -IncludeReferencedProjects -Prop Configuration=Release

but they don't work.但他们不工作。 I'm not sure which one is more suited.我不确定哪个更适合。

Are there more suited alternatives?有更合适的替代品吗?

I'd personally recommend using a .nuspec file - using a project only as a container to ship multiple assemblies together without any behavior at all doesn't seem right to me.我个人建议使用.nuspec文件 - 仅将项目用作容器将多个程序集一起运送而没有任何行为对我来说似乎不合适。
Such a .nuspec would look like this:这样的.nuspec看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <id>My.Package</id>
        <version>1.0.0</version>
        <description>My package</description>
        <authors>Me</authors>
        <dependencies>
            <group targetFramework="netstandard2.0" />
        </dependencies>
    </metadata>
    <files>
        <file src="*\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0" />
    </files>
</package>

And you have to call nuget pack .\.nuspec (using PowerShell).你必须调用nuget pack .\.nuspec (使用 PowerShell)。

The newer approach would be to not use .nuspec at all, but ship the three projects as three independent NuGet packages.较新的方法是根本不使用.nuspec ,而是将三个项目作为三个独立的 NuGet 包发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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