如何从 Nuget 包中移除 DLL(s)?

huangapple go评论88阅读模式
英文:

How do i remove dll(s) from Nuget package?

问题

我使用Visual Studio 2022并根据这篇文章创建了一个Nuget包。

https://arsenshnurkov.github.io/gentoo-mono-handbook/building-nupkg.htm

我运行了nuget pack并看到了nupg文件,然后将其上传到我们的Azure Artifacts。以下是spec文件的内容:

<package>
  <metadata>
    <id>myProject.csproj</id>
    <version>1.0.0</version>
    <authors>user</authors>
    <owners>user</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Test package 1</description>
    <releaseNotes>Summary of changes.</releaseNotes>
    <copyright>Copyright 2023</copyright>
    <tags>Tag test</tags>
  </metadata>
</package>

我注意到当我将此包安装到测试应用程序时,它包含了一些不需要的dll文件,这些文件对最终项目的运行不是必需的。

经过一些研究,有建议在打包时更改.csproj文件以将其从Nuget中排除。可以参考以下文章:https://www.jocheojeda.com/2019/07/22/how-to-exclude-package-dependencies-in-a-nuget-package/

但是他提到了与我相同的问题,但没有提供如何操作的示例。在文章中,他引用了以下内容:

“答案取决于您现在如何创建NuGet包,如果您是根据csproj文件中的信息创建包(如果使用nuspec文件则有不同的方法),那么我将专注于在csproj文件中排除依赖项。”

不想修改csproj文件,只想修改nuspec文件。如何通过修改nuspec文件来排除我不希望与我的包捆绑在一起的文件?

英文:

Im using Visual Studio 2022 and created a Nuget Package using this article

https://arsenshnurkov.github.io/gentoo-mono-handbook/building-nupkg.htm

I run nuget pack and i see the nupg file and upload it to our Azure Artifacts. Below is the spec file

&lt;package &gt;
  &lt;metadata&gt;
    &lt;id&gt;myProject.csproj&lt;/id&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
    &lt;authors&gt;user&lt;/authors&gt;
    &lt;owners&gt;user&lt;/owners&gt;
    &lt;requireLicenseAcceptance&gt;false&lt;/requireLicenseAcceptance&gt;
    &lt;description&gt;Test package 1&lt;/description&gt;
    &lt;releaseNotes&gt;Summary of changes.&lt;/releaseNotes&gt;
    &lt;copyright&gt;Copyright 2023&lt;/copyright&gt;
    &lt;tags&gt;Tag test&lt;/tags&gt;
  &lt;/metadata&gt;
&lt;/package&gt;

I noticed when i install this pack into a test application it includes some dlls that are not required for the end project to run.

After some research there are suggestions to change the .csproj to exclude it from Nuget when packing following this article https://www.jocheojeda.com/2019/07/22/how-to-exclude-package-dependencies-in-a-nuget-package/

but he writes the exact question i have in mind but no example of how to do this. In the article he quotes

the answer depend on how now you create your NuGet package, in this case, I’m going to focus my answer on excluding the dependency in a package created by the info in the csproj file (there is a different approach if you use the nuspec file).

I dont want to amend the csproj file but just the nuspec file. How could i leave out files that i dont want to have bundled with my package by amending the nuspec file?

答案1

得分: 0

为了在NuGet打包中包含/排除文件,您可以按照此处描述的方式将<files>部分添加到nuspec配置文件中。

根据您的示例,这些文件将排除包中的日志文件。使用通配符,您可以排除任何其他文件/dll:

<package>
<metadata>
<id>myProject.csproj</id>
<version>1.0.0</version>
<authors>user</authors>
<owners>user</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Test package 1</description>
<releaseNotes>Summary of changes.</releaseNotes>
<copyright>Copyright 2023</copyright>
<tags>Tag test</tags>
</metadata>
<files>
<file src="." exclude="*.log" />
</files>
</package>

英文:

In order to include/exclude files from nuget packaging, you can add the <files> section to nuspec config file as described here.

Following your example, the files would exclude log files from your package. Using wildcards, you can exclude any other file/dll:

&lt;package&gt;
	&lt;metadata&gt;
	&lt;id&gt;myProject.csproj&lt;/id&gt;
	&lt;version&gt;1.0.0&lt;/version&gt;
	&lt;authors&gt;user&lt;/authors&gt;
	&lt;owners&gt;user&lt;/owners&gt;
	&lt;requireLicenseAcceptance&gt;false&lt;/requireLicenseAcceptance&gt;
	&lt;description&gt;Test package 1&lt;/description&gt;
	&lt;releaseNotes&gt;Summary of changes.&lt;/releaseNotes&gt;
	&lt;copyright&gt;Copyright 2023&lt;/copyright&gt;
	&lt;tags&gt;Tag test&lt;/tags&gt;
	&lt;/metadata&gt;
	&lt;files&gt;		
		&lt;file src=&quot;*.*&quot; exclude=&quot;*.log&quot; /&gt;
	&lt;/files&gt;
&lt;/package&gt;

huangapple
  • 本文由 发表于 2023年1月9日 17:33:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定