2016-08-19 71 views

回答

3

有4個步驟可將NPOI庫添加到.NET Core項目中。

  1. 添加net451爲下在project.json文件的框架性的依賴,包括對NPOI庫的引用:

    "frameworks": { 
    "netcoreapp1.0": { 
        "imports": [ 
        "dotnet5.6", 
        "portable-net45+win8" 
        ] 
    }, 
    "net451": { 
        "dependencies": { 
         "NPOI": "2.2.1" 
        } 
        } 
    }, 
    
  2. project.json文件,添加runtimes作爲頂級性能:

    "runtimes": { 
    "win7-x64": {}, 
    "win7-x86": {}, 
    "osx.10.11-x64": {}, 
    "ubuntu.14.04-x64": {}, 
    "centos.7-x64": {}, 
    "rhel.7.2-x64": {}, 
    "debian.8-x64": {} 
    } 
    
  3. project.json文件中,從頂部級屬性dependencies

    "Microsoft.NETCore.App": { 
        "version": "1.0.0", 
        "type": "platform" 
    }, 
    
  4. project.json文件中刪除Microsoft.NETCore.App屬性,取出下頂層的netcoreapp1.0屬性frameworks屬性:

    "netcoreapp1.0": { 
        "imports": [ 
        "dotnet5.6", 
        "portable-net45+win8" 
        ] 
    }, 
    

實施例完整的project.json文件:

{ 
    "userSecretsId": "aspnet-MyProjectName-xxxxxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxxxx", 

    "dependencies": { 
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0", 
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0", 
    "Microsoft.AspNetCore.Mvc": "1.0.0", 
    "Microsoft.AspNetCore.Razor.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0", 
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", 
    "Microsoft.EntityFrameworkCore.SqlServer.Design": { 
     "version": "1.0.0", 
     "type": "build" 
    }, 
    "Microsoft.EntityFrameworkCore.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 
    "Microsoft.Extensions.Configuration.Json": "1.0.0", 
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0", 
    "Microsoft.Extensions.Logging": "1.0.0", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0", 
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", 
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0", 
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "MailKit": "1.4.1" 
    }, 

    "tools": { 
    "BundlerMinifier.Core": "2.0.238", 
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", 
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", 
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final", 
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "imports": [ 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "frameworks": { 
    "net451": { 
     "dependencies": { 
     "NPOI": "2.2.1" 
     } 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "configProperties": { 
     "System.GC.Server": true 
    } 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "Views", 
     "Areas/**/Views", 
     "appsettings.json", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "prepublish": [ "bower install", "dotnet bundle" ], 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    }, 

    "runtimes": { 
    "win7-x64": {}, 
    "win7-x86": {}, 
    "osx.10.11-x64": {}, 
    "ubuntu.14.04-x64": {}, 
    "centos.7-x64": {}, 
    "rhel.7.2-x64": {}, 
    "debian.8-x64": {}  
    } 
} 
+0

在這裏要明確..你已經採用.NET核心應用程序,並將其轉換爲標準的asp.net應用程序,對嗎? IOW,.net核心功能已被刪除。 – paqogomez

+0

@paqogomez這是正確的。當我這樣做時,我想使用新的.net核心應用程序項目類型。這允許我在單個項目中使用DI容器和MVC/Web API控制器。現在我相信有一個網絡標準項目可以爲你提供所有這些。但是當我這樣做的時候沒有。 – AperioOculus

相關問題