【问题标题】:Creating a new package and adding it ot nuget source in Visual Studio在 Visual Studio 中创建一个新包并将其添加到 nuget 源
【发布时间】:2021-02-10 15:47:36
【问题描述】:

我有一个 Asp.Net MVC 解决方案,需要添加为 Nuget 包,供内部应用程序作为共享组件使用。

我google了一下,发现我们只能使用类库.项目来创建nuget包。 就我而言,如何使用 Web 应用程序创建 nuget 包?还是应该创建一个引用 Asp.Net MVC 应用程序 dll 的类库项目?

以前,整个应用程序作为 dll 被其他组件/项目引用。现在我需要将此 dll 移动到 nuget 源,以便通过从 nuget 管理器下载它仍然可以被其他项目使用。

提前致谢。

【问题讨论】:

  • 你想达到什么目的?作为 nuget 包的整个 Web 应用程序对我来说毫无意义。如果您尝试将您的应用程序插入另一个应用程序,请查看 MVC 区域。
  • 以前,整个应用程序作为 dll 被其他组件/项目引用。现在我需要将此 dll 移动到 nuget 源,以便通过从 nuget 管理器下载它仍然可以被其他项目使用。

标签: asp.net-mvc nuget nuget-package


【解决方案1】:

您可以添加一个 .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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-03
    • 1970-01-01
    • 2017-06-17
    • 2020-02-24
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多