问题描述
我对.Net Core还是很陌生,但是已经创建了一个可正常使用的Asp.Net Core WebAPI网站-现在,我想与另一个项目共享一些代码...
I'm fairly new to .Net Core, but have made a working Asp.Net Core WebAPI site - now I want to share some code with another project...
- 我安装了带有Update 3的Visual Studio 2015.
- 我从此处安装了DotNetCore.1.0.0-VS2015Tools.Preview2.exe.
- I have Visual Studio 2015 with Update 3 installed.
- I have DotNetCore.1.0.0-VS2015Tools.Preview2.exe installed from here.
我想创建一个共享库(PCL),其他两个库可以使用它-它仅包含基本类/接口,而没有其他依赖项.其中一个使用的库是针对"netstandard1.6"的新的香草项目,另一个是针对.Net 4.5.2的旧客户端库(如果需要的话,我可以将其升级到4.6.x).
I would like to create a shared library (PCL) that can be consumed by two other libraries - it only contains primitive classes/interfaces with no other dependencies. One of the consuming libraries is a new vanilla project targeting "netstandard1.6", the other is an old client library which targets .Net 4.5.2 (I can upgrade this to 4.6.x if I must).
我已经转了一圈,而且我不能让netstandard1.6库引用PCL-我只是被告知类型缺失:
I've been round in circles, and I can't make the netstandard1.6 library reference the PCL - I just get told the types are missing:
名为"ClassLibrary1"的PCL的project.json将自动生成为:
The PCL named "ClassLibrary1"'s project.json is auto-generated as:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.1": {}
}
}
我的消耗类库project.json是:
My consuming library project.json is:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"netstandard1.6": {
"dependencies": {
"ClassLibrary1": {
"target": "project"
}
}
}
}
}
我该如何进行这项工作?
How can I make this work?
编辑2016年7月7日:
EDIT 07/07/2016:
我提供了以下解决方案,用以说明我的设置: https://github.com/JonnyWideFoot/netcore-prototype 有关我想在.Net 4.5.2/4.6.x客户端中使用合同库的位置,请参见ExperimentClient :: GetLocationAsync.
I have made the following solution available, which demonstrates my setup:https://github.com/JonnyWideFoot/netcore-prototypeSee ExperimentClient::GetLocationAsync for where I would like to use the Contracts Library within the .Net 4.5.2 / 4.6.x Client.
推荐答案
我发现实现此目的的唯一方法是破解对客户端库的.csproj文件的引用: https ://github.com/JonnyWideFoot/netcore-prototype/blob/master/src/JE.API.Experiment.Client/JE.API.Experiment.Client.csproj
The only way I have found to make this work, is to hack reference the .csproj file of the Client library:https://github.com/JonnyWideFoot/netcore-prototype/blob/master/src/JE.API.Experiment.Client/JE.API.Experiment.Client.csproj
<Reference Include="JE.Api.Experiment.Contract, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\JE.Api.Experiment.Contract\bin\$(Configuration)\net452\JE.Api.Experiment.Contract.dll</HintPath> </Reference>
<Reference Include="JE.Api.Experiment.Contract, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\JE.Api.Experiment.Contract\bin\$(Configuration)\net452\JE.Api.Experiment.Contract.dll</HintPath> </Reference>
通过对合同库中的正确输出文件夹的路径进行硬编码,一切都很好.
By hard-coding the path to the correct output folder from the contracts library, all is fine.
...认为这可能是Visual Studio中的错误.
... thinking this could be a bug in visual studio.
这篇关于.NET Core和.Net 4.5.2都使用的通用类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!