【发布时间】:2015-02-26 13:06:46
【问题描述】:
我正在将现有解决方案迁移到 ASP.NET vNext。我的解决方案是传统的 N 层应用程序。考虑到这一点,该解决方案有四个项目。这四个项目是这样组织的:
/backend
/library
Sample.cs
project.json
/web
project.json
/test
/library
SampleTest.cs
project.json
/web
project.json
global.json
简而言之,web 项目引用了library 项目。 /test/library/ 项目旨在测试library 项目。 /test/web/ 项目旨在测试web 项目。我的问题是,我似乎无法从我的test 项目中引用library 项目。如果我尝试在 library 中引用一个类,我会收到一条错误消息:
System.IO.FileLoadException: Could not load file or assembly 'library' or one of
its dependencies. General Exception (Exception from HRESULT: 0x80131500)
System.IO.FileLoadException: Could not load file or assembly 'library' or one of
its dependencies. General Exception (Exception from HRESULT: 0x80131500)
File name: 'library' ---> Microsoft.Framework.Runtime.Roslyn.RoslynCompilationEx
ception: C:\Projects\MySolution\test\library\SampleTest.cs(21,7
): error CS0246: The type or namespace name 'Sample' could not be found (
are you missing a using directive or an assembly reference?)
这是我的相关文件的内容
/backend/library/project.json
{
"version":"3.0.0.0",
"description":"This is the app library",
"compilationOptions": {
"warningsAsErrors": true
},
"dependencies": {
"Microsoft.Data.Common":"0.1.0.0-alpha-build-0137"
},
"code": [ "**\\*.cs", "..\\Shared\\*.cs" ],
"frameworks": {
"net45": {}
}
}
/backend/library/Sample.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace MySolution.Library
{
public class Sample
{
public int Id { get; set; }
public string Name { get; set; }
public void Save()
{
}
}
}
/test/library/project.json
{
"commands": {
"test": "Xunit.KRunner"
},
"dependencies": {
"Xunit.KRunner": "1.0.0-beta1"
},
"frameworks": {
"aspnet50": { },
"aspnetcore50": { }
}
}
/test/library/SampleTest.cs
using System.IO;
using Microsoft.Framework.Runtime;
using Xunit;
namespace MySolution.Library
{
public class SampleTest
{
[Fact]
public void Save()
{
Sample sample = new Sample();
sample.Save();
Assert.NotNull(sample);
}
}
}
global.json
{
"sources": [ "backend/library" ]
}
我做错了什么?为什么我似乎无法从我的 test 项目中引用我的 library 项目?
谢谢!
【问题讨论】:
标签: c# asp.net asp.net-core