简体   繁体   English

创建一个基本的NuGet包

[英]Creating a basic NuGet Package

I have a small c# library that wraps Dapper.net and I want to create a nuget package for this library. 我有一个包装Dapper.net的小型c#库,我想为这个库创建一个nuget包。 I've created a folder that contains the following: 我创建了一个包含以下内容的文件夹:

Nuget-Package\
Nuget-Package\Package.nuspec
Nuget-Package\lib\
Nuget-Package\lib\DapperWrapper.dll

Here's the nuspec 这是nuspec

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>GoDaddy.Data</id>
    <version>1.0.0</version>
    <authors>Owner Name</authors>
    <owners>Owner Name</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>I provide a fast and slim layer between your code and stored procedures that your application needs to use. This layer provides more straight-forward access to procs than straight ADO and less overhead than using Entity or Linq. It currently uses Dapper.Net to do some of this work.</description>
    <releaseNotes>Initial Release</releaseNotes>
    <copyright>Copyright 2014</copyright>
    <tags>ADO Dapper Proc "Stored Procedure"</tags>
    <dependencies>
      <dependency id="Dapper" version="1.13" />
    </dependencies>
  </metadata>
</package>

I then copy the resulting DapperWrapper1.0.0.0.nupkg over to my local nuget server. 然后,我将生成的DapperWrapper1.0.0.0.nupkg复制到我的本地nuget服务器。

After this I attempt to install it on a console application. 在此之后,我尝试将其安装在控制台应用程序上。 I open a simple console application right click on references and say manage nuget packages. 我打开一个简单的控制台应用程序,右键单击引用并说管理nuget包。 I find and select my package and select install and get the following error: 我找到并选择我的包并选择安装并获得以下错误:

Attempting to resolve dependency 'Dapper (≥ 1.13)'.
External packages cannot depend on packages that target projects.

What am I doing wrong here? 我在这做错了什么?

Seems too simple to fail and yet I cant seem to find a good explanation of this error anywhere. 似乎太简单到失败,但我似乎无法在任何地方找到这个错误的一个很好的解释。

The answer can be found here. 答案可以在这里找到。 http://www.marcusoft.net/2011/12/creating-tools-only-nuget-package.html http://www.marcusoft.net/2011/12/creating-tools-only-nuget-package.html

Apparently nuget wont resolve dependencies unless you have both "lib" and "content" folders even if you're not using them. 显然nuget不会解决依赖关系,除非你同时拥有“lib”和“content”文件夹,即使你没有使用它们。

Wow that's a bug IMO. 哇,这是一个错误的IMO。

See this nuget workitem: http://nuget.codeplex.com/workitem/595 请参阅此nuget工作项: http ://nuget.codeplex.com/workitem/595

You could try adding a files section to your nuget package, referencing the files in your project. 您可以尝试将文件部分添加到nuget包中,引用项目中的文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM