Issue with NuGet Package Manager - nuget

I have a project that I recently converted over to use Entity Framework. I installed the package on my development machine and everything worked perfectly and I continued to re-vamp the project.
I recently pushed out the first update to my production server with the Entity Framework code in it. When I tried to build the solution it threw all kinds of errors, namely this one over and over:
Could not resolve this reference. Could not locate the assembly "EntityFramework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. bamblack.viewmodel
I went into my NuGet Package Manager, and it says EntityFramework was installed. I then tried to install it through the Package Manager Console, said the same thing. So I then tried to uninstall it. It says it can't locate the package!
I'm sure it's because I didn't do the actual install on the production machine and it's just missing a DLL somewhere, but I'm not sure where. If anyone could point me in the right direction that would be great.

Seems that all I needed to do was un/reinstall the references to EF on my development machine and push it out again. Strange that it didn't push them out the first time. Issue was resolved.

Related

Microsoft.Windows.SDK.Contracts and Must Use PackageReference

It's been a while since I've gotten into nuget hell but I'm back to this again...
I'm not exactly sure what caused this issue other than I did a visual studio 2019 update before I left on Friday. Now today, I've been fighting an issue where my library won't compile due to "Must Use PackageReference".
I've found a few articles out there on this but nothing that seems to specifically address this problem.
This issue could also be due to accidentally adding some .netcore librairies (entity framework .core) to the .netframework library. I had a hard time removing those libraries using nuget.
I also tried to reload the nuget library by:
nuget-package -reinstall Microsoft.Windows.SDK.Contracts
That reloads the package ok, but when I recompile the library the error "Must use PackageReference" comes back again.
In the output window I have this when compiling:
...\path...\packages\Microsoft.Windows.SDK.Contracts.10.0.19041.1\build\Microsoft.Windows.SDK.Contracts.targets(4,5): error : Must use PackageReference
I'm not even seeing this referenced in any of my source files so I'm not sure I even need it. However, I can't uninstall it as it seems to have octopus tentacles in numerous other libraries.
What am I running into here and how do I get this resolved?
My fix was to convert the projects to PackageReference as seen here: https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference The problem went away after doing this and I haven't seen it since. Still a little uneasy on why this happened... But I don't have time to dwell on it.

Azure-DevOps clone shows references as warnings

Cloning a project and it looks like it comes down fine, until I look in the references and they all have the yellow warning triangle. Then my Error List shows all the references as Warnings. My application is on Visual Studio 2017 and it is MVC with C# coding using .NET Framework 4.7.2. In my normal application, original, the references are perfectly fine and no errors and it works great. Builds and works fine. Once I bring down the clone is then the references are lost. I've done a build on the cloned version and it shows all the references as warnings.
I've double clicked a reference and received an error popup box of "This project cannot be viewed in the object browser because it is unavailable or not yet built. Please ensure that the project is available and built". It feels like Azuredev-ops is just missing my references and their location. I am the only one working on this, so there should be no conflicts. I've posted and cloned right after posting, with same result. My code and Web configs look just fine. I have cloned on other people's system too, and same problem with this application. FYI, many of my other applications are working fine using the clone. Just 1 application is having issues. My references are separated in that some are Copy Local True while others are False. I've also removed a reference and added it back, and it comes back with a warning as if it were never added.
Warning message for individual reference:
The referenced component 'EntityFramework' could not be found.
I am also seeing errors for NuGet packages not being there, but when I look I see the package folder with all it's components in it.
It says that for all my windows core references. And just warning symbols in my reference folder for other references.
I am expecting no errors when I bring down the clone. I've upload using my machine and cloning should be able to use the same reference locations. It just feels like AzureDev-Ops is stripping my reference links out, and then going I can't find them.
Azure-DevOps clone shows references as warnings
To resolve this issue, you should make sure of the following:
Make sure you have checked those two options Allow NuGet to download missing packages and Automatically check for missing packages during build in Visual Studio:
Make sure you do not check the \packages folder to the source control.
When you clone the project from Azure-DevOps server and get missing reference error, you should use the NuGet command line Update-Package -reinstall in the Package Manager Console to force reinstall the package references into project. Check this thread for some more info.
Note: Especially need to pay attention to the third point.
Update:
Error:Mircrosoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0
According to the error message, it seems you are not add your packages to your packages source in Visual Studio.
You should publish your custom packages to the nuget feed or you can create you local nuget feed, then add the nuget feed path or local feed path to the package source:
Check this document for some more details.
Hope this helps.
I figured it out. I went to my original and did the Update-Package -reinstall. It came back with the Microsoft.CodeDom.Providers.DotNetCompiler.Platform.2.0.0 not there, but it added one, just not 2.0.0. Then I ran an uninstall of the Microsoft.CodeDom.Providers.DotNetCompiler removing it from my system. Then I posted my original up to AzureDev-ops. My clone came down, not all the references were messed up, some were still, but I did a rebuild and that cleared it up. Thank you to the responses, it pointed me in the right direction.

Error when adding views to MVC .NetCore project

I am very new to EntityFramework development, not to mention to .NetCore and MVC design pattern, I actually started with .NetCore development with a introduction book to those subjects, I reached a chapter where the autor starts with an MVC project (still using .NetCore 2.0) and do Scaffolding to create the EF model based on a Database previously created, then he jumps to add a controller via wizard, chosing the option that says: "MVC Controller with views, using Entity Framework", but when I do this, a get the error:
"There was an error running the selected code generator: ' Failed to
update dependency information for the project. Please restore the
project and try again."
I tried adding this files manually and detected that this happens when I try (or the wizard tries) to create the view file, either using an empty template or using one of the models, the result is the same.
I thought it was for the NuGet packages that where "asking" for updates, so I updated them, but nothing changed, I recreated the project several times, trying to leave the NuGet packages versions that the autor mentions to install, and to have "everything up to date" but still got the same.
I found another question in here with the same problem, and tried the possible solutions that mentions there, but none worked for me, I even try to install the versions 2.0.0 (or the lowest if there where no version 2.0.0) of the NuGet packages needed (or rather, mentioned by the author), and there was a change, still an error, but a different one, that says that the Microsoft.AspNetCore.Razor.Design.targets file needs a value on Configuration...?, still not know what to do, I noticed that updating 3 packages eliminates this error but is going back to the views error.
I don't know what else can I do or how to address this problem.
I finally made it work, although at the end, I don't know what was the problem, what I did was to uninstall all the NuGet packages, then reinstall one by one, chosing the 2.0.0 versions of each one (or the lowest if there was no 2.0.0 version) until there where no sintax errors (by the way, I already had done this, but I don't know what changed) and ended up with 13 packages installed, after verifying that the project builds correctly, I tried again to add via wizard the controller and the view and it threw another error asking to update just two packages (EntityFrameworkcore and EntityFrameworkCore.Design) to versions 2.0.3, after that, I was able to add both the controller and the views with no problem at all and the project still builds correctly.

AutoMapper 6.2.2 restore fails on VSTS build server

The Restore step fails in my build definition with this error:
error NU1100: Unable to resolve 'AutoMapper (>= 6.2.2)' for '.NETCoreApp,Version=v2.0'.
This is in a .NETCoreApp 2.0 that is using AutoMapper. Restore succeeds locally in VS 2017. Locally I am using dotnet sdk 2.0.0, and nuget 4.3.1. On the VSTS (cloud) server, I am specifying the latest nuget version, 4.5.0. I have tried many other versions, including 4.3.1 with no success.
I know there is an older, similar question here, but that was never answered satisfactorily, in my opinion.
If I look at the meta data in VS, at the top of one of the Automapper files I can see this:
Assembly AutoMapper, Version=6.2.2.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005
// C:\Users\randyg.nuget\packages\automapper\6.2.2\lib\netstandard1.3\AutoMapper.dll
From this you can see it's taking the netstandard1.3 version, which is correct. I'm wondering if the nuget on the build server is looking for a netcoreApp2.0 folder, rather than the netstandard1.3 folder? Following this theory, I tried adding this to my .csproj file:
<AssetTargetFallback>$(AssetTargetFallback);netstandard1.3</AssetTargetFallback>
My theory was this would tell nuget to look for a netstandard1.3 version of automapper if it couldn't find a netcoreapp2.0 version. However, this didn't have any effect. I later read that behind the scenes this fallback is already added automatically.
If anyone has any ideas I would greatly appreciate it. I'm pulling out (what's left of) my hair on this, as this is the only package giving me trouble, and it's a critical one for my project.
On the build server I'm using .NET Core sdk 2.0.3 as well, if that matters.
This is how I solved this: since it seemed it might have to do with my target being netcoreapp2.0, I tried adding an additional 'dummy' project to my solution, with its target = netstandard1.3. In this configuration, the restore/build succeeded. I thought I would have to maintain this dummy project for this purpose, until I tried deleteing it and now the netcoreapp2.0 solution still restores fine without it. I can only assume something was corrupted in the TFS build server NPM cache (even though I had tried checking the box to disable that cache), and once I got it to succeed once, it has cleared up whatever the issue was.

nuget - package restore not working

My aim is to have package restore working on a build server so that I don't have to check in binaries. At the moment, I'm simply trying to get it to work on my own machine using Visual Studio.
Here's what I've done so far:
Followed the instructions here http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages, including both setting the Tools-Options flag and the environment variable (belt and braces)
Installed the NuGetEnablePackageRestore package as suggested here NuGet package restore consent without NuGet
Checked everything in (the .nuget solution folder and its contents), but not the binaries I want to reference, because that's the whole point of the exercise
Here's what I'm doing:
Check out solution
Verify that nunit.framework.dll and moq.dll are not present in the checked out solution
Build the solution
Visual Studio complains that Moq is missing. I search for the dlls in the solution directory and find that:
nunit.framework.dll is present in the appropriate bin folders
Moq.dll is nowhere to be found
But there's more. This is truly mysterious, but if I do a fresh checkout, disconnect from the internet and build, I get precisely the same results - nunit.framework.dll is there, but moq.dll is not. The build process has conjured nunit.framework.dll literally from nowhere.
So it's something of an understatement to say that I am completely baffled. Can anyone suggest answers to the following questions:
Why is package restore not downloading Moq?
Where on earth is the build process getting nunit.framework.dll, if not the internet?
In vs, Options, Package Manager... there's a section "Package Cache", if you click on the "Browse" button it will take you to the location of the nuget cache in your machine.
Okay, I noticed in the documentation that enabling package restore was supposed to modify project files in order to add a new target. My project files did not have this change. Right-clicking the solution title in VS and selecting 'Manage NuGet packages...' then added the required changes and everything built as it should.
I checked, and package restore still appears to work when I have no internet access, so I'm still mystified about that. Does NuGet maintain some kind of cache of binaries outside the solution?