从.NET Core项目中添加对PCL(目标为.NET 4.6和.NET Core)的引用是否可能?
我尝试创建了这两种类型的项目,但是如果我从.NET Core项目向PCL添加引用,它无法识别任何名称空间。但是它能够编译成功。
下面是project.json文件:
PCL:
{
"supports": {
"net46.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452"
}
}
}
.NET Core:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"dependencies": {
"ClassLibrary1": { // <-- Reference to the PCL
"target": "project"
}
},
"imports": "dnxcore50"
}
}
}
编辑:
不知道是否有用,这里是所请求的构建输出:
Restoring NuGet packages...
To prevent NuGet from restoring packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages during build.'
1>------ Build started: Project: ClassLibrary2, Configuration: Debug Any CPU ------
1> C:\Program Files\dotnet\dotnet.exe build "C:\ClassLibrary2\ClassLibrary2" --configuration Debug --no-dependencies
1> Project ClassLibrary2 (.NETStandard,Version=v1.6) will be compiled because inputs were modified
1> Compiling ClassLibrary2 for .NETStandard,Version=v1.6
1> Compilation succeeded.
1> 0 Warning(s)
1> 0 Error(s)
1> Time elapsed 00:00:00.8914597
1>
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
编辑 2:
好吧,我至少已经成功构建了它,但现在我遇到了一个关于无法找到System.Runtime的运行时错误。奇怪的是,在测试解决方案中它可以工作,但不能在我想要实施它的解决方案中工作。
供参考,这里是我的project.json文件:
PCL:
{
"supports": {},
"dependencies": {
"Microsoft.CSharp": "4.0.1",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0",
"System.Runtime.Serialization.Primitives": "4.1.1"
},
"frameworks": {
"net451": {},
"netstandard1.5": {}
}
}
.NET Core:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50",
"dependencies": {
"PclTest": {
"target": "project"
},
"System.Runtime": "4.1.0"
}
}
}
}