在.Net核心预发布版本上间接依赖框架程序集

时间:2016-11-10 17:32:26

标签: .net asp.net-core .net-core

我正在使用.Net Core的predelase版本进行一些实验。

我正在使用.Net Core的 1.0.0-preview4-004071 版本。 安装.NET Core SDK,在 C:\ Program Files \ dotnet \ shared \ Microsoft.NETCore.App 中创建 1.0.3 文件夹,并为相同的构建版本添加二进制文件(全部从 https://github.com/dotnet/cli#installers-and-binaries 下载。

我的* .csproj文件是:

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

<PropertyGroup>
   <OutputType>Exe</OutputType>
   <TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
   <Compile Include="**\*.cs" />
   <EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
   <PackageReference Include="Microsoft.NETCore.App">
   <Version>1.0.3</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
   <Version>1.0.0-alpha-20161104-2</Version>
   <PrivateAssets>All</PrivateAssets>
</PackageReference> 
</ItemGroup>        
<Reference Include="System.Collections.Specialized"/>
<Reference Include="System.Collections.NonGeneric">
   <SpecificVersion>False</SpecificVersion>
   <HintPath>Lib\System.Collections.NonGeneric.dll</HintPath>
</Reference>
<Reference Include="System.Resources.ResourceManager"> 
   <SpecificVersion>False</SpecificVersion>  
   <HintPath>Lib\System.Resources.ResourceManager.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

在Lib文件夹下,我有来自同一版本的DLL的副本。

我正在尝试使用 System.Collections.Specialized System.Collections.NonGeneric DLL(尝试从默认路径和Lib文件夹获取)但是收到类似这样的警告:

C:\Program Files\dotnet\sdk\1.0.0-preview4-004071\Microsoft.Common.CurrentVersion.targets(1909,5): warning MSB3268: The primary reference "System.Collections.NonGeneric" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "System.Collections.NonGeneric" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". 

C:\Program Files\dotnet\sdk\1.0.0-preview4-004071\Microsoft.Common.CurrentVersion.targets(1909,5): warning MSB3268: The primary reference "System.Collections.NonGeneric" could not be resolved because it has an indirect dependency on the framework assembly "System.Diagnostics.Debug, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "System.Collections.NonGeneric" or retarget your application to a framework version which contains "System.Diagnostics.Debug, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

如果我是正确的问题是msbuild无法找到正确的程序集并查找不正确的路径。

如何修复装配路径查找?

1 个答案:

答案 0 :(得分:1)

必须将.Net Core的引用添加为包而不是像这样的DLL:

<PackageReference Include="System.Reflection.Emit">
  <Version>4.0.1</Version>
</PackageReference>