简体   繁体   English

Nugets安装在visual studio 2015中

[英]Nugets install in visual studio 2015

I try to install the nuget Microsoft.VisualStudio.QualityTools.UnitTestFramework in Visual Studio 2015 in simple project and got this message: 我尝试在简单的项目中在Visual Studio 2015中安装nuget Microsoft.VisualStudio.QualityTools.UnitTestFramework并得到以下消息:

Could not install package 'Microsoft.VisualStudio.QualityTools.UnitTestFramework 10.0.30319.1'. 无法安装包'Microsoft.VisualStudio.QualityTools.UnitTestFramework 10.0.30319.1'。 You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. 您正在尝试将此软件包安装到以“.NETFramework,Version = v4.5.2”为目标的项目中,但该软件包不包含任何与该框架兼容的程序集引用或内容文件。 For more information, contact the package author. 有关更多信息,请与软件包作者联系。

But, when I try to install this package in Visual Studio 2013 in the same project this is work. 但是,当我尝试在Visual Studio 2013中在同一个项目中安装此软件包时,这是有效的。

How can I install this nuget in Visual Studio 2015? 如何在Visual Studio 2015中安装此nuget?

Time has passed, but it is happening to me, and I have found that it has nothing to do with the framework version. 时间已过,但它发生在我身上,我发现它与框架版本无关。 The important text of the error message is: "...but the package does not contain any assembly references or content files...". 错误消息的重要文本是:“...但包不包含任何程序集引用或内容文件......”。

Indeed, my package does not have any visible content for Nuget: it has a non conventional folder with third party native libraries and a Install.ps1 that adds a post build event with a Xcopy command. 实际上,我的包没有Nuget的任何可见内容:它有一个带有第三方本机库的非常规文件夹和一个带有Xcopy命令的后期构建事件的Install.ps1。

As an easy turnaround, just put a dummy file in the package Content folder or any other dummy content in lib, empty file node (not tried it), etc. 作为一个简单的转变,只需将一个虚拟文件放在包Content文件夹或lib中的任何其他虚拟内容,空文件节点(未尝试过)等。

EDIT 29/5/2017 编辑29/5/2017

I am seeing that this answer is useful to others, and that is why I am going to elaborate a little more. 我看到这个答案对其他人有用,这就是为什么我要再详细说明一下。

As I said, the problem is that Nuget don't see there is any content in the package, but it may have two causes: 正如我所说,问题是Nuget没有看到包中有任何内容,但它可能有两个原因:

  1. The package really does not have visible content because it moves the content with a script, etc. (as it was my case), and then it is necessary to create some dummy content as a workaround. 该软件包确实没有可见内容,因为它使用脚本等移动内容(就像我的情况一样),然后有必要创建一些虚拟内容作为变通方法。

  2. There's a mistake in the specification of a package that must have content (as was the case of Evgeni Nabokov in the comments), and then you have to correct the specification to put things in place. 在必须具有内容的包的规范中存在错误(如评论中的Evgeni Nabokov的情况),然后您必须更正规范以将内容放置到位。

Sorry for my bad english. 对不起,我的英语不好。

The error message is saying you that there is no version of nuget for your framework version. 错误消息告诉您框架版本没有nuget版本。

In VS2013 You probably create the project in 4.5.0 or 4.0.0 version of .Net framework. 在VS2013中,您可能在4.5.0或4.0.0版本的.Net框架中创建项目。

Have you tried to change .Net version of your project to 4.5.2 ? 您是否尝试将项目的.Net版本更改为4.5.2?

This might happen when the .NET standard of the solution and the corresponding NuGet package mismatch. 当解决方案的.NET标准和相应的NuGet包不匹配时,可能会发生这种情况。 Here is a table from this link : 这是这个链接的表格:

╔════════════════════════════╦═══════════════════════════════════════════════════════════════╗
║ .NET Platform              ║ .NET Standard                                                 ║
╠════════════════════════════╬═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦═══════╣
║                            ║  1.0  ║  1.1  ║  1.2  ║  1.3  ║  1.4  ║  1.5  ║  1.6  ║  2.0  ║
╠════════════════════════════╬═══════╬═══════╬═══════╬═══════╬═══════╬═══════╬═══════╬═══════╣
║ .NET Core                  ║   →   ║   →   ║   →   ║   →   ║   →   ║   →   ║  1.0  ║ vNext ║
║ .NET Framework             ║   →   ║  4.5  ║ 4.5.1 ║  4.6  ║ 4.6.1 ║ 4.6.2 ║ vNext ║ 4.6.1 ║
║ Xamarin.iOS                ║   →   ║   →   ║   →   ║   →   ║   →   ║   →   ║   →   ║ vNext ║
║ Xamarin.Android            ║   →   ║   →   ║   →   ║   →   ║   →   ║   →   ║   →   ║ vNext ║
║ Universal Windows Platform ║   →   ║   →   ║   →   ║   →   ║ 10.0  ║   →   ║   →   ║ vNext ║
║ Windows                    ║   →   ║  8.0  ║  8.1  ║       ║       ║       ║       ║       ║
║ Windows Phone              ║   →   ║   →   ║  8.1  ║       ║       ║       ║       ║       ║
║ Windows Phone Silverlight  ║  8.0  ║       ║       ║       ║       ║       ║       ║       ║
╚════════════════════════════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╝

You have to match both the framework and .NET standard version. 您必须匹配框架和.NET标准版本。 I prefer .NET standard 1.4 and .NET Framework 4.6.1. 我更喜欢.NET标准1.4和.NET Framework 4.6.1。 By creating the .NET Standard, Microsoft is codifying the requirement of having consistent APIs across all .NET platforms. 通过创建.NET标准,Microsoft正在编写在所有.NET平台上拥有一致API的要求。 It seems like once you migrate your solutions to these level of compatibility, "incompatibility" or discovering the wheel again after each update will be a memory of the past. 看起来,一旦您将解决方案迁移到这些兼容性级别,“不兼容”或在每次更新后再次发现轮子将成为过去的记忆。

I had this issue when building my nuget packages in TeamCity, publishing them in local artifactory and then trying to use those packages in other projects. 在TeamCity中构建我的nuget包时,我遇到了这个问题,在本地工件中发布它们,然后尝试在其他项目中使用这些包。

In Order to avoid this issue - in TeamCity, BuildSteps ==> NuGet Pack ==> Package parameters ==> Specification files you have to select .csproj file over nuspec file and tick option "Prefer project files to .nuspec" 为了避免这个问题 - 在TeamCity,BuildSteps ==> NuGet Pack ==>包参数==>规范文件中你必须选择.csproj文件而不是nuspec文件并勾选选项“首选项目文件到.nuspec”

The package that build like that will be just fine to import and no more complaints from VS. 像这样构建的软件包可以很好地导入,不再需要来自VS的投诉。

I got this and it made no sense because I was already using it no problem on a framework 4.6 project and the error told me it wouldn't work on framework 4.6 which I knew to be untrue. 我得到了这个并没有任何意义,因为我已经在框架4.6项目中使用它没有任何问题,并且错误告诉我它不适用于我知道不真实的框架4.6。

In the end I solved it by making another test project, copying the cs files etc from my old test project and then installing UnitTestFramework through NuGet. 最后,我通过制作另一个测试项目,从旧的测试项目中复制cs文件等,然后通过NuGet安装UnitTestFramework来解决它。 It works fine. 它工作正常。

So something happens that only microsoft can solve I would guess but starting again seems to fix it. 所以有一些事情发生,只有微软可以解决,我猜,但重新开始似乎解决它。

It seems that creating a "Unit Test Project" instead of "Class Library" solves the problem. 似乎创建“单元测试项目”而不是“类库”解决了这个问题。 I fighted with the "Class Library" with no luck, but removing that project an creating a new one from the "Unit Test Project" template became with the Microsoft.VisualStudio.QualityTools.UnitTestFramework version 10.0.0.0 installed. 我没有运气地使用“类库”,但删除该项目,从“单元测试项目”模板创建一个新项目变为安装了Microsoft.VisualStudio.QualityTools.UnitTestFramework版本10.0.0.0。

I found that the DynamicInterop.0.8.1.nupkg has the dll file in a folder 'lib\\netstandard1.2'. 我发现DynamicInterop.0.8.1.nupkg在文件夹'lib \\ netstandard1.2'中有dll文件。 I just changed the folder name to lib\\net40 and the package would install ok (Im using VS2013). 我刚刚将文件夹名称更改为lib \\ net40,并且包安装正常(我使用的是VS2013)。 Also: the .nupkg is just a .zip file, so any zip tool lets you manipulate the contents. 另外:.nupkg只是一个.zip文件,因此任何zip工具都可以让你操作内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM