0
votes

I have Solution A which has a .NET Core 1.1 class library project. In the Package properties I filled all NuGet fields and selected to create the NuGet upon successful build. This project builds just fine and the NUPKG is created. BTW How can I automatically copy the generated NUPKG to a local directory (my own repository)?

Then I have Solution B which is an ASP.NET Core 1.1 web application. 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. VS.2017 says it was successful at installing it. I see it listed in the project's NuGet dependencies.

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!

What is causing this Visual Studio generated Nuget package to be installed and yet act as if it has not even been referenced?

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). I finally figured out why it did not work, the ItemGroup must be inside the 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:

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). 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

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?

1
Are you supplying the proper "using" statements to get access to the namespaces?Erik Funkenbusch
By the way, you should either create a local Nuget server, or use a shared file location, then add that location to your Nuget sources. Then you can just build and copy it to the folder, and then you can use "Update" in Nuget manager to get newer versions.Erik Funkenbusch
Yes of course I put the using statement. Even tried fully qualifying the names but it does not even recognize the top level namespace of that NuGet, as if it was installed but then not really, yet it is listed as dependency.Lord of Scripts
Have you checked the contents of the nuget package to see if the DLL's are actually included? You can simply rename the .nupkg as .zip and use any zip tool to look insideErik Funkenbusch
@ErikFunkenbusch Yes, I did as well as you can see in my OP update above. The DLL is there and the embedded stuff appears there only I see it in two places: content (old style) and contentFiles (.net core)Lord of Scripts

1 Answers

1
votes

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.

Of all the Visual Studios I have used since 2002 this has been the most unstable! (and I have update 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".

So I went to my C:\Users\AppData\USER\Local\Microsoft\VisualStudio\15.2* folder and removed it completely.

After that I the ACCESS DENIED issue went away with the side effect that I had to reinstall all extensions again. 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.