asp.net-mvc - Creating a new package and adding it ot nuget source in Visual Studio
问题描述
I have a Asp.Net MVC solution, that needs to be added as a Nuget package, which can be used as a shared component by internal applications.
I have googled a bit and found that we can create a nuget package only by using a class library. project. In my case how can I create a nuget package using a web application ? Or should I create a class library project referencing the the Asp.Net MVC application dll ?
Previously this whole application as a dll was referenced by other components/ projects. Now I need to move this dll to the nuget source so that it can be still used by other projects by downloading it from nuget manager.
Thanks in advance.
解决方案
您可以添加一个 .nuspec 文件来定义您的 dll 及其依赖项,并添加一个构建后调用来创建包。
示例 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"
推荐阅读
- python - 如何使用 Python Selenium 将任何网页翻译成英文并保存其完整的网页截图?
- amazon-web-services - AWS 支持每个 ALB 侦听器的多个目标组
- php - 如何在 PHP 中合并两个不相等的多维数组?
- arrays - 我想将标题返回给每个数组而不是一组数字。JSON解码斯威夫特
- express - Stripe CLI 触发随机事件而不是 payment_intent.succeeded
- tsc - 如何在 lerna monorepo 中使用 lint-staged 在所有包中运行相同的命令?
- javascript - JS时区错误偏移
- excel - Power Query 编辑器中的动态列名问题
- java - 在 Spring Tools 4 (Eclipse) 中创建 Spring MVC 项目
- swiftui - Swift UI 如何从子视图中检索状态