.net core 一次坑爹的類庫打包過程


眾所周知,.net core 跨平台類庫引用一定要通過nuget獲得。(如有問題,歡迎指出)

打包

將普通.net project轉換成.net core 的類庫有兩種方式:

1.新建.net core 的類庫 -》 把原所有文件拷貝過來 -》 在project.json中解決依賴包問題 -》編譯打包

2.新建.net core 的類庫 -》 在project.json中配置源文件include complie, 如下:

 1  "frameworks": {
 2     "netstandard1.6": {
 3       "imports": "dnxcore50",
 4       "buildOptions": {
 5         "compile": {
 6           "include": [ "../MongoDB.Driver/**/*.cs", "../MongoDB.Shared/Hasher.cs" ]
 7         },
 8         "define": [ "DEBUG", "TRACE" ],
 9         "warningsAsErrors": true,
10         "outputName" : "MongoDB.Driver",
11         "xmlDoc": true
12       }
13     }
14   }

通過buildOptions的comple的include,把原來文件路徑引用過來

-》 編譯project, 通過cmd命令切換到project目錄

-> dotnet build

-》 打成nuget包

-> dotnet pack

這樣,在原bin/debug目錄下面會多出nuget包文件。

 

引用

坑爹就坑在引用上。

通過反復驗證,一個package包無論引用了多少其他程序集(包括自定義的),只需發布最終需要的package就可以了,因為依賴關系都已經在里面了。如下圖:

我的MongoDB.Driver.Dotnet引用了MongoDB.Bson.Dotnet和MongoDB.Driver.Core.Dotnet,打包的時間只需MongoDB.Driver.Dotnet就可以了。

依賴關系都在打包的MongoDB.Driver.Dotnet.nuspec文件里

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>MongoDB.Driver.Dotnet</id>
    <version>1.0.0</version>
    <authors>MongoDB.Driver.Dotnet</authors>
    <owners>MongoDB.Driver.Dotnet</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>MongoDB.Driver.Dotnet</description>
    <tags></tags>
    <dependencies>
      <group targetFramework=".NETStandard1.6">
        <dependency id="MongoDB.Bson.Dotnet" version="[1.0.0, )" />
        <dependency id="MongoDB.Driver.Core.Dotnet" version="[1.0.0, )" />
        <dependency id="NETStandard.Library" version="[1.6.0, )" />
        <dependency id="System.Linq.Expressions" version="[4.1.0, )" />
        <dependency id="System.Linq.Queryable" version="[4.0.1, )" />
      </group>
    </dependencies>
  </metadata>
</package>

但這不是坑爹的地方,坑就坑在nuget在本地會有緩存在以下目錄中

C:\Users\%Local User%\.nuget\packages

如果重新打包沒有升級版本號,單純在服務器端切換nuget包是沒有的,一定要把本地也清空了。。

目測是2015升級到最新版本才有的問題,因為我之前服務器直接替換沒遇到過這樣類似的問題,stackoverflow的這位仁兄也是

http://stackoverflow.com/a/33214933


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM