简体   繁体   English

如何使用msbuild 15从生成的nuget包中的nuspec文件中删除依赖项部分

[英]How to remove the dependencies section from nuspec file in the generated nuget package using msbuild 15

I use msbuild v15.8.168.64424 (vs 2017.8) commandline to build nuget package for console application. 我使用msbuild v15.8.168.64424(vs 2017.8)命令行为控制台应用程序构建nuget软件包。 I used ILMerge to merge all dependencies, so I get only one exe file without dependencies. 我使用ILMerge合并所有依赖项,因此我只得到一个没有依赖项的exe文件。

When runing the command 运行命令时

        msbuild project1.csproj /t:build /p:configuration=release /p:IsTool=true

I get the nuget package, but when inspecting it, I find the dependencies section . 我得到了nuget包,但是在检查它时,我发现了dependencies section

     <dependencies>
           <group targetFramework=".NETFramework4.5">
            <dependency id="lib1" version="1.3.0" exclude="Build,Analyzers" />
            <dependency id="lib2" version="2.3.0" exclude="Build,Analyzers" />              
          </group>
        </dependencies>

I want the `dependencies section to be empty (because I merged all the dependencies). 我希望`dependencies'部分为空(因为我合并了所有依赖项)。

I can use nuspec file to generate the package without dependencies section, but the drawback is passing manually all the metadata which is included in csproj. 我可以使用nuspec文件来生成无依赖项部分的程序包,但是缺点是手动传递了csproj中包含的所有元数据。 I didn't find a property for the dependencies in pack target inputs 我没有在包目标输入中找到依赖项的属性

The Question: 问题:

How I remove the dependencies section from the nuspec file which is included in the generated nuget package? 如何从生成的nuget包中包含的nuspec文件中删除依赖项部分?

You can set the metadata PrivateAssets="All" on the package or project references ( <PackageReference> / <ProjectReference> ) in the csproj file to exclude them as NuGet dependencies. 您可以在csproj文件中的程序包或项目引用( <PackageReference> / <ProjectReference> )上设置元数据PrivateAssets="All" ,以将它们排除为NuGet依赖项。

Note that this change needs a restore so perform a NuGet restore in between or add -restore to the MSBuild invocation. 请注意,此更改需要还原,因此请在两者之间执行NuGet还原或将-restore添加到MSBuild调用中。

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

相关问题 如何在生成的 .nuspec 的 MSBuild NuGet 包中注入自定义依赖项 - How to inject a custom dependency in an MSBuild NuGet pack generated .nuspec 如何在官方nuget服务器上访问nuget包的nuspec文件? - How to get access to nuspec file of a nuget package on official nuget server? 无法使用 dotnet CLI 和 nuspec 文件打包 NuGet 包 - Unable to pack a NuGet package using dotnet CLI and nuspec file Roslyn 分析器 package 的 NuGet 依赖项是否不可能存在? - Is it impossible to have NuGet-dependencies at .nuspec of a Roslyn analyzer package? 从nuspec文件的不同文件夹中包含的多个csproj创建多目标nuget包 - Create multi-target nuget package from several csproj contained in different folders from nuspec file 使用NuGet Pack时,是否可以指定没有nuspec文件的软件包名称? - When using NuGet Pack is it possible to specify the package name without a nuspec file? exe文件在nuget package中的位置和nuspec中的匹配文件标签 - location of exe file in nuget package and matching file tag in nuspec 如何在创建 Nuget package 时在 nuspec 文件中正确指定依赖信息? - How to correctly specify dependency information in nuspec file while creating Nuget package? Nuspec for NuGet包与UWP项目 - Nuspec for NuGet package with UWP project 如何从私有NuGet提要中获取NuGet包的依赖项? - How to get the dependencies of a NuGet package from private NuGet feed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM