简体   繁体   English

VIsual Studio 2017 NuGet软件包安装良好,但无法识别

[英]VIsual Studio 2017 NuGet package installs well but is not recognized

I have Solution A which has a .NET Core 1.1 class library project. 我有解决方案A,它具有.NET Core 1.1类库项目。 In the Package properties I filled all NuGet fields and selected to create the NuGet upon successful build. 在Package属性中,我填写了所有NuGet字段,并选择在成功构建后创建NuGet。 This project builds just fine and the NUPKG is created. 该项目构建良好,并且创建了NUPKG。 BTW How can I automatically copy the generated NUPKG to a local directory (my own repository)? 顺便说一句,我如何自动将生成的NUPKG复制到本地目录(我自己的存储库)?

Then I have Solution B which is an ASP.NET Core 1.1 web application. 然后,我有了解决方案B,它是ASP.NET Core 1.1 Web应用程序。 In it I browse to my local repository (where I have manually copied the NUPKG built by Solution A) and install my SolutionA.MyPackage into the web application. 在其中,我浏览到本地存储库(已在其中手动复制了由解决方案A构建的NUPKG),并将我的SolutionA.MyPackage安装到Web应用程序中。 VS.2017 says it was successful at installing it. VS.2017表示已成功安装。 I see it listed in the project's NuGet dependencies. 我在项目的NuGet依赖项中看到了它。

However, when I try to use ANY of the objects defined in that NuGet package I get a red highlight saying it is not found as if there was no NuGet or assembly reference to that DLL but there is! 但是,当我尝试使用该NuGet包中定义的任何对象时,都会得到红色突出显示,表明未找到该对象,就好像没有NuGet或该DLL的程序集引用一样!

What is causing this Visual Studio generated Nuget package to be installed and yet act as if it has not even been referenced? 是什么原因导致此Visual Studio生成的Nuget软件包被安装,却好像没有被引用一样起作用?

UPDATE - CSPROJ TARGET As for copying to my local repository, I added this to CSPROJ but it was not working (somebody had suggested it as I put it). 更新-CSPROJ目标至于复制到我的本地存储库中,我将其添加到CSPROJ中,但是它不起作用(有人按我的建议提出了建议)。 I finally figured out why it did not work, the ItemGroup must be inside the Task. 我终于弄清楚了为什么它不起作用, ItemGroup必须在 Task中。

  <Target Name="CopyPackage" AfterTargets="GenerateNuspec">
     <ItemGroup>
        <MyPackageFiles Include="bin\Release\PackageId.*.nupkg" />
     </ItemGroup>
     <Copy SourceFiles="@(MyPackageFiles)" DestinationFolder="D:\My Repository\MyNugget\Publish" />
  </Target>

UPDATE NuGet Inspection I opened the NUPKG with NuGet Package Explorer and it shows this more or less: 更新NuGet检查我使用NuGet包资源管理器打开了NUPKG,它或多或少显示了这一点:

content\
        Properties\
           launchSettings.json
        Views\
           Shared\
              rest of my stuff here
contentFiles\
   any\
     netcoreapp1.1\
        Properties\
           launchSettings.json
        Views\
           Shared\
              rest of my stuff here
lib\
   netcoreapp1.1 (.NEtCoreApp, Version=v1.1)
         MyPackage.dll

UPDATE 3 Since NuGet seems to have stopped working (used to work well earlier) I opted for using an Assembly Reference rather than a NuGet (for now). 更新3由于NuGet似乎已停止工作(以前可以正常工作),因此我选择使用程序集引用而不是NuGet(目前)。 In this situation something odd happens, when coding I can reference ALL the objects in the referenced assembly (former NuGet) and therefore no compilation errors on the main project BUT when I then run the web application I get an internal error because it says 在这种情况下,会发生一些奇怪的事情,在编码时,我可以引用所引用程序集中的所有对象(以前的NuGet),因此在我运行Web应用程序时,在主项目BUT上没有编译错误,我得到一个内部错误,因为它说

FileNotFoundException: Could not load file or assembly 
'MyPackage, Version=0.0.3.0, Culture=neutral, PublicKeyToken=null'. 
The system cannot find the file specified.

 Unknown location

Which is strange because in the Solution Explorer I see the assembly reference and when I click on it (main application) I can navigate to all the objects that I have defined in that assembly. 这很奇怪,因为在解决方案资源管理器中,我看到了程序集引用,当我单击它时(主应用程序),我可以导航到该程序集中定义的所有对象。 Why it cannot find it anymore? 为什么它找不到了?

It is working again (as it was before!). 它再次正常工作(就像以前一样!)。 Today I could open the solutions but when I tried to download an extension (Tools | Extensions) I got an error message about an Access Denied or something like that. 今天,我可以打开解决方案,但是当我尝试下载扩展程序(工具|扩展程序)时,我收到有关拒绝访问或类似问题的错误消息。 It has happened before since I installed to VS.2017. 自从我安装到VS.2017以来,这已经发生了。

Of all the Visual Studios I have used since 2002 this has been the most unstable! 自2002年以来我使用的所有Visual Studio中,这是最不稳定的! (and I have update 15.2). (并且我有更新15.2)。

When I saw this error happening again I knew how to get rid of it and thought, "hey, maybe that is what is keeping the NuGet package to be installed but not found or the problem with a direct assembly reference". 当我再次看到此错误再次发生时,我知道如何消除此错误,并想:“嘿,也许这是使NuGet软件包得以安装但未找到的原因,或者是直接组装参考的问题”。

So I went to my C:\\Users\\AppData\\USER\\Local\\Microsoft\\VisualStudio\\15.2 * folder and removed it completely . 因此,我进入了C:\\ Users \\ AppData \\ USER \\ Local \\ Microsoft \\ VisualStudio \\ 15.2 *文件夹并将其完全删除

After that I the ACCESS DENIED issue went away with the side effect that I had to reinstall all extensions again. 此后,ACCESS DENIED问题消失了,而副作用是我不得不再次重新安装所有扩展。 I attempted again to install my own NuGet, it did so successfully and as expected (was not happening during the long glitch) the objects were found and the web application worked again. 我再次尝试安装自己的NuGet,它成功完成了安装,并且按预期进行了安装(在长时间的故障中没有发生),找到了对象,并且Web应用程序再次工作。

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

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