2016-10-22 104 views
3

在Visual Studio 2015 Update 3中,我根據Full .NET Framework和包含我的域模型的.net類庫項目創建了一個ASP.NET Core項目。如何從完整的.Net框架測試項目引用ASP.NET Core項目?

然後我創建了一個單元測試項目(與ms-test),以測試我的控制器和我的域對象。以下是目錄結構:

Proj 
|-src 
    |-WebProj 
|-DomainProj 
|-TestProj 

我能夠通過使用測試項目下的References項目來引用asp.net核心Web項目作爲依賴項。

問題是來自asp.net核心項目的類型在Test項目中不可用(類型或名稱空間名稱無法找到錯誤)。

我在電腦上找到了以下問題:How to reference an ASP.NET 5 project from another project? 但它不是很有幫助;在引用Web項目的測試項目中創建一個project.json文件不能解析類型。

我應該創建一個單獨的.Net核心測試項目來測試asp.net核心項目嗎?

UPDATE 這裏是WebProj的project.json文件:

{ 
    "userSecretsId": "xxxxx", 

    "dependencies": { 
    "BundlerMinifier.Core": "2.2.281", 
    "Microsoft.AspNet.Mvc": "5.2.2", 
    "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.1", 
    "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.1", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0", 
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", 
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1", 
    "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" 
    } 
    }, 

    "tools": { 
    "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": { 
    "net452": { 
     "dependencies": { 
     "CodeGenProj": { 
      "target": "project" 
     }, 
     "DomainProj": { 
      "target": "project" 
     } 
     } 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": 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%" ] 
    } 
} 
+2

我認爲你不能做到這一點。爲什麼你需要創建完整的.net框架測試項目?爲什麼不用Xunit框架創建.net核心測試項目? Xunit是支持.net核心的第一個框架之一。檢查[this](https://xunit.github.io/docs/getting-started-dotnet-core.html)out –

+0

請從.NET Core項目中發佈project.json文件。 –

+0

@ShaunLuttin我發佈了project.json – Chedy2149

回答

相關問題