如何把Nuget 打包给别人

小熊 Windows1 2,044阅读模式

首先需要知道一些 Nuget 打包需要知道的,请看 win10 uwp 上传Nuget 让别人用我们的库

但是 UWP 的包和上面说的有一些不同,需要对打包做一些修改。小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

可以到 csdn 下载 Nuget 的程序或者到https://www.nuget.org/downloads下载小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

创建空白的spec

使用 Nuget 命令在空白的文件夹进行创建空白的包,使用命令nuget spec小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

假如下载的 Nuget 放在 E:\ ,空白文件是 “E:\1” 那么使用的命令就是进入空白文件夹,然后需要写 Nuget 的路径才可以使用。按win+R输入 cmd 打开命令行,然后输入下面代码小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

E: 进入E盘
cd 1 进入1文件夹
然后把 Nuget 拉进命令行
E:\nuget.exe spec

这时可以看到命令行输出 成功创建小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

E:\1>E:\nuget.exe spec
已成功创建“Package.nuspec”。

可以看到现在存在 Package.nuspec文件,打开他可以看到下面的东西小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

<?xml version="1.0"?>
<package >
  <metadata>
    <id>Package</id>
    <version>1.0.0</version>
    <authors>lindexi</authors>
    <owners>lindexi</owners>
    <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
    <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
    <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2017</copyright>
    <tags>Tag1 Tag2</tags>
    <dependencies>
      <dependency id="SampleDependency" version="1.0" />
    </dependencies>
  </metadata>
</package>

如果你已经看过我上面的博客,那么就知道这些东西是可以如何写,但是 UWP 有一些不同,我现在没有使用上面博客的方法可以成功上传,于是就需要做一些修改。小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

对空白spec进行修改

首先是版本,现在的版本和id什么都需要自己写,也就是上面的内容都需要自己全部写。如果需要在 description 使用换行,直接回车就好。如果自己的库需要依赖,那么请修改 dependencies ,依赖的版本参见小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

 小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

创建简单的库

上面写的叫 metadata ,写完之后可以创建一个新的 UWP 库,我在这创建一个叫 NrzlmhRzvy 的库小熊资源网小熊资源网-https://www.xxzyweb.com/11.html

在里面创建一个类

批量创建不同平台 dll 可以给不同的需要

右击解决方法批处理

可以看到有很多的方法,点全选

点击重新生成

可以看到生成了很多文件

打包

接下来就是创建 Nuget ,首先需要把空白的包放到库的文件夹,这里创建的库是E:\1\NrzlmhRzvy\所以把Package.nuspec放在E:\1\NrzlmhRzvy,现在使用 SublimeText打开这个spec,对他做一些修改

<?xml version="1.0"?>
<package >
  <metadata>
    这里不写
  </metadata>
  <files>
     这里写文件
  </files>

</package>

添加文件就是写文件的放在哪,在使用nuget会按照放在的位置,在不同的平台使用库,如果写错了,使用这个库的程序就无法使用,这里需要添加的文件有不同平台的,请看下面的代码

        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.dll" target="runtimes\win10-arm\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-arm\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.pri" target="runtimes\win10-arm\lib\uap10.0"/>

        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.dll" target="runtimes\win10-x64\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-x64\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.pri" target="runtimes\win10-x64\lib\uap10.0"/>

        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.dll" target="runtimes\win10-x86\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-x86\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.pri" target="runtimes\win10-x86\lib\uap10.0"/>

还需要添加入口,现在的代码如果使用,就会出现 提供了编译时引用程序集,但没有与 win10-arm 兼容的运行时程序集 所以需要添加 ref 请看下面

        <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.dll" target="ref\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.pdb" target="ref\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.pri" target="ref\uap10.0"/>

于是现在的 spec 就是下面的代码

<?xml version="1.0"?>
<package >
   <metadata>
    <id>Package</id>
    <version>1.0.0</version>
    <authors>lindexi</authors>
    <owners>lindexi</owners>
    <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
    <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
    <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2017</copyright>
    <tags>Tag1 Tag2</tags>
    <!-- <dependencies>
      <dependency id="SampleDependency" version="1.0" />
    </dependencies> -->
  </metadata>
  <files>
        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.dll" target="runtimes\win10-arm\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-arm\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.pri" target="runtimes\win10-arm\lib\uap10.0"/>

        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.dll" target="runtimes\win10-x64\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-x64\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.pri" target="runtimes\win10-x64\lib\uap10.0"/>

        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.dll" target="runtimes\win10-x86\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-x86\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.pri" target="runtimes\win10-x86\lib\uap10.0"/>

          <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.dll" target="ref\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.pdb" target="ref\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.pri" target="ref\uap10.0"/>

     </files>
</package>

然后尝试使用本地的库,新建另一个项目,打开Nuget命令行,输入下面的代码

install-package Package -Source E:\1\NrzlmhRzvy

或者点击选项打开 Nuget 管理,输入本地地址

如何把Nuget 打包给别人

这样就可以添加打包的库,安装之后需要重新编译才可以使用

如果发现安装还没发现这个程序的类,那么重新编译可能就可以使用。如果发现安装提示不兼容,找不到库,就需要升级库的版本,然后重新生成。

但是这样可以看到,虽然库可以使用,但是没有注释,因为生成没有注释,如果需要注释,那么需要在库右击属性,生成,输出 xml ,实际上输出一份就好了,自己把他复制到各个平台。

或者在生成那里点击输出 xml文档,选择所有的平台,然后修改包的内容,添加输出的xml,这样就可以使用注释

下面就是整个spec的内容

<?xml version="1.0"?>
<package >
   <metadata>
    <id>lindexi</id>
    <version>1.0.2</version>
    <authors>lindexi</authors>
    <owners>lindexi</owners>
    <licenseUrl>http://lindexi.oschina.io</licenseUrl>
    <projectUrl>http://lindexi.oschina.io</projectUrl>
    <iconUrl>http://lindexi.oschina.io</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description> description</description>
    <releaseNotes></releaseNotes>
    <copyright>Copyright 2017</copyright>
    <tags>Tag1 </tags>
  </metadata>
  <files>
          <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.dll" target="runtimes\win10-arm\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-arm\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.XML" target="runtimes\win10-arm\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\ARM\Debug\NrzlmhRzvy.pri" target="runtimes\win10-arm\lib\uap10.0"/>

        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.dll" target="runtimes\win10-x64\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-x64\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.XML" target="runtimes\win10-x64\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x64\Debug\NrzlmhRzvy.pri" target="runtimes\win10-x64\lib\uap10.0"/>

        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.dll" target="runtimes\win10-x86\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.pdb" target="runtimes\win10-x86\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.XML" target="runtimes\win10-x86\lib\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\x86\Debug\NrzlmhRzvy.pri" target="runtimes\win10-x86\lib\uap10.0"/>

          <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.dll" target="ref\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.pdb" target="ref\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.pri" target="ref\uap10.0"/>
        <file src=".\NrzlmhRzvy\bin\Debug\NrzlmhRzvy.XML" target="ref\uap10.0"/>

     </files>
</package>
继续阅读
 最后更新:2022-1-21
Windows

4K Video Downloader v4.23.1.5220

4K Video Downloader(4K视频下载器)油管高清视频下载利器,可提取视频字幕和音乐,智能下载高清画质视频,一键下载字幕,订阅YouTube视频,下载所有油管频道及列表。它是一款...
Windows

UVR5人声伴奏分离

是一款开源免费的伴奏人声提取软件,你可以从音乐中免费提取伴奏或是音乐,网上有很多专业的软件,但是大多是商业需要付费的,而Ultimate Vocal Remover则是免费的,同时也开源!它使...
Windows

洛雪音乐助手v1.20.1绿色版

洛雪音乐助手桌面版,全网付费歌曲版权音乐下载软件。聚合大量音乐平台搜索接口,免费在线试听下载全网付费歌曲版权音乐;挖掘酷狗音乐歌单、酷我音乐排行榜;可选音乐来源接口,下载歌词、专辑封面等。 ...
    • 小熊
      小熊 3

      自己顶一下 :mrgreen:

    匿名

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
    确定

    取消

    拖动滑块以完成验证