如何解决在Visual Studio中创建一个新程序包并将其添加到nuget源
我有一个Asp.Net MVC解决方案,该解决方案需要作为Nuget软件包添加,可以由内部应用程序用作共享组件。
我在Google上搜索了一下,发现我们只能使用类库。项目来创建nuget包。 就我而言,如何使用Web应用程序创建nuget包?还是应该创建一个引用Asp.Net MVC应用程序dll的类库项目?
以前,整个应用程序以dll格式被其他组件/项目引用。现在,我需要将此dll移至nuget源,以便通过从nuget管理器下载该dll仍可被其他项目使用。
谢谢。
解决方法
您可以添加一个.nuspec文件来定义您的dll及其依赖项,并向create the package添加一个后构建调用。
示例nuspec文件:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" >
<metadata>
<id>myproductid</id>
<version>$version$</version>
<title>some title</title>
<authors>me</authors>
<owners>myself</owners>
<projectUrl>http://www.example.com</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>...</description>
<releaseNotes>First nuget release.</releaseNotes>
<copyright>Copyright 2020</copyright>
<dependencies>
<dependency id="AutoMapper" version="9.0.0" />
<dependency id="jQuery" version="3.3.1" />
<dependency id="Microsoft.AspNet.Mvc" version="5.2.7" />
<dependency id="Microsoft.AspNet.Razor" version="3.2.7" />
<dependency id="Newtonsoft.Json" version="12.0.2" />
<dependency id="System.Reflection.TypeExtensions" version="4.6.0" />
</dependencies>
</metadata>
<files>
<file src="bin\My.WebApplication.dll" target="lib\net461" />
</files>
</package>
就我而言,后期构建事件如下所示:
if ($(Configuration)) == (Release) nuget pack "$(ProjectPath)" -Prop Configuration=Release -OutputDirectory "K:\nuget"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。