在.net 4.6.2中使用.net标准1.5 lib缺少System.Runtime 4.1.0.0 [英] Using .net standard 1.5 lib in .net 4.6.2 misses System.Runtime 4.1.0.0

查看:111
本文介绍了在.net 4.6.2中使用.net标准1.5 lib缺少System.Runtime 4.1.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.net Framework 4.6.2 consoleapps中使用.net标准时,我遇到了一些问题。

I've some problem when using .net standard in .net framework 4.6.2 consoleapps.

我可以将问题简化为:
给定:

I could reduce the problem to this: Given:

我使用这个单一类创建了一个.net标准的1.5客户端库,相对于2017年

I create a .net standard 1.5 client library vis vs 2017 with this single class

public class Class1
    {
        public List<int> Get()
        {
            return new List<int>() { 1, 2, 3, 4, 5, 65, 6 };
        }
    }

现在,我创建一个新的.net 4.6.2控制台仅调用此类方法的应用程序:

Now I create a new .net 4.6.2 console application which is just calling the method of this class:

       static void Main(string[] args)
        {
            var foo = new Class1();

            Console.WriteLine("Done!");
            Console.ReadLine();
        }

现在我得到

System.IO.FileNotFoundException:'文件或程序集
System.Runtime,版本= 4.1.0.0,区域性=中性,
PublicKeyToken = b03f5f7f11d50a3a未找到

System.IO.FileNotFoundException: 'The File or Assembly "System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a was not found

当我将.net standardlib nuget程序包添加到.net fx控制台时,它可以工作,但是system.runtime可以通过GAC和通过nuget参考,这对我来说似乎很丑。

When I add the .net standardlib nuget package to the .net fx console it works. but then the system.runtime would be aviable via GAC and via nuget reference which seems to be quite ugly for me.

我在这里推送了这个简短的测试解决方案: https://github.com/Gentlehag/NetStandardSample

I pushed this short test solution here: https://github.com/Gentlehag/NetStandardSample

我缺少什么?

推荐答案

我添加了 repo ,向您展示如何执行此操作。从README.md:

I've added a repo that shows you how to do this. From the README.md:


要求



一般来说ng,在应用程序中使用面向.NET Standard的库。针对.NET Framework的
要求应用程序项目包括针对.NET Standard的NuGet
引用( NETStandard.Library )。这样可以确保应用程序中包含正确的
程序集。

Requirements

Generally speaking, using libraries targeting .NET Standard in an application targeting .NET Framework requires the application project to include a NuGet reference for .NET Standard (NETStandard.Library). This ensures that the right set of assemblies are included with the application.

在Visual Studio 2015中,从.NET $ b中使用NuGet包的默认方式$ b Framework项目是通过 packages.config 完成的。我不建议使用此路径,因为
意味着所有程序集都直接注入到应用程序
项目中,这会极大地膨胀您的项目文件。相反,我建议
使用 project.json 。为此,请执行以下步骤:

In Visual Studio 2015, the default way of consuming NuGet packages from .NET Framework projects is via packages.config. I don't recommend this path as this means that all assemblies are directly injected into the application project, which will significantly bloat your project file. Instead, I recommend you use project.json. To do this, perform the following steps:


  1. 卸载所有软件包(如果您仍在使用 packages.config

  2. 删除空的 packages.config

  3. 添加具有以下内容的 project.json 文件:

json
{
dependencies:{
NETStandard.Library: 1.6.0
},
运行时间:{
win:{}
},
frameworks:{
net462:{}
}
}

请注意,通常您可以依赖
NETStandard.Library的最新版本。 / code>包,但您需要确保将
框架的名称与您应用定位的.NET Framework版本保持同步,即,将.b.b定位为
时4.6.1,您需要确保使用
net461 来代替。

Please note that you can generally depend on the latest version of the NETStandard.Library package, but you need to make sure to keep the framework moniker in sync with the version of .NET Framework your app is targeting, i.e. when you're targeting .NET Framework 4.6.1, you need to make sure to use net461 instead.

是的。我们计划以两种方式解决此问题:

Yes it is. We're planning on addressing this in two ways:


  • 我们正在替换 project.json 和Visual
    Studio 2017中基于MSBuild的解决方案。您仍然需要将引用添加到 NETStandard.Library ,但是
    您不再需要弄乱包的表示方式,也不必
    手动保持定位信息同步。

  • We're replacing project.json with an MSBuild based solution in Visual Studio 2017. You'll still need to add the reference to NETStandard.Library, but you no longer have to mess with the way packages are being represented nor having to manually keep targeting information in sync.

计划更新.NET Framework,以使其将来的版本附带对.NET Standard的
内置支持,在这种情况下,将不再需要

We're planning to update .NET Framework so that future version of it come with built-in support for .NET Standard, in which case the reference will no longer be needed.

这篇关于在.net 4.6.2中使用.net标准1.5 lib缺少System.Runtime 4.1.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆