Visual studio 2019 auto removed nuget packages after debug - c#

Every time I add any nuget package to my .net core application, it stays for a bit but it seems like after I start a debug and end it, the nuget package removed automatically from Visual studio project.
Is any thing changes in visual studio 2019?

After searching on internet I found solution on this developer community Website.
Close VS2019
Delete the ".vs" folder
Open VS2019, add the NuGet package
Save all
I suspect "Save all" after adding a NuGet package might be key here.

You should see: In the NuGet.Config file, DisabledPackageSources tag shows you the sources which are currently disabled, so if you want to make them be active, add the sources under the ActivePackageSource. Anyway, since it works well now after you edit the DisabledPackageSources, at least, we make sure that it would be related to the NuGet.Configfile.

Related

Visual Studio 2017: References are mentioned not being built while they are already built

I'm working with Visual Studio 2017, enterprise version. I'm working on a C# project, depending on several NuGet packages.
One of my references is mentioned being missing (there's a yellow triangle above the icon in the solution explorer). When I double-click on it, in order to see its contents in the object browser, I get following error message:
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.
You might think: "just restore the package (it's a NuGet package) and off you go", but the problem is that the message makes no sense:
In another project, I am using the exact same NuGet package as a reference, there everything is fine, and when I do a file/directory compare between that other project and my current one, WinMerge mentions both being equal. (Not only WinMerge, I also did a checksum comparison)
So my question is: what's the source of Visual Studio's This project cannot be viewed in the object browser because it is unavailable or not yet built. error message? What's the source of the yellow triangle in Visual Studio's solution explorer (for NuGet packages)?
Edit (added: Visual Studio version)
For your information, I'm working with Visual Studio enterprise 2017, version 15.9.36.
In the meantime I've found a workaround: I remove the references from the project and add them again, and it seems to work. Apparently there's some instability in Visual Studio reference handling.

How to clone a Xamarin Project and have it build right away

I am working on a project on my laptop, and am switching laptops. It is a Xamarin Android project with C#. It is source controlled onto visual studio online / devops using the Git option. When I clone my project onto my new laptop. My project is not building. Some projects aren't loading and some of my references have errors next to them.
I think to get it working requires some necessary steps. Please tell me if any of this should not be necessary.
(1) Open Visual Studio Installer and Modify in order to add Mobile Development and .Net so that Xamarin is installed.
(2) Tools > Android > Android SDK Manager > Checkmark necessary SDKs (aka android Lollipop, etc). (If these are failing, then right click on visual studio icon to "Run as Administrator" when initially opening.
This third step is whats bothering me:
(3) Clean Solution and Rebuild. And magically every dependency and every necessary anything is automatically installed/etc.. but not true.
Instead...
Some references in your projects will have a yellow triangle icon. Go to Tools > Nuget Package Manager and when you select any of the Installed projects, there will NOT be a checkmark next to ANY projects.. weird.. but when you go to Update, and click on any needing an update, the checkmark will be there. If you select all and update, some of your yellow triangles will go away, but the checkmarks won't appear in Installed when clicking on a project and seeing which projects it is installed in on the right.
Is there some button or command I am supposed to run that will grab all the necessary dependencies for me? Instead of me having to dig around and still have a non working solution?
Can you give some examples of the error messages you are getting? Usually Project Load - Restore Nuget Packages - Clean & Rebuild works for me.
NuGet will download the packages available in the package manager. However it may happen that some packages where not installed through the sources available in the package manager or that those packages are not available anymore.
In order for all the projects to build correctly I believe the following order is necessary: (As OP, I downloaded and tried to build the project before checking to make sure I had Xamarin and the necessary SDKs, and once those were installed, it wouldn't fix the project without deleting and recloning)
(1) Do NOT clone your project from github/devops yet. Delete it if you have.
(2) Install Xamarin. Open Visual Studio Installer and Modify in order to add Mobile Development and .Net so that Xamarin is installed.
(3) Install necessary SDKs for Android OS version. Tools > Android > Android SDK Manager > Checkmark necessary SDKs (aka android Lollipop, etc). (If these are failing, then right click on visual studio icon to "Run as Administrator" when initially opening.
(4) Clone project from github/devops, and clean/build. Should work automatically.
(An aside: I feel like step 3 should also be automatic? It should know which ones I'm targeting and auto install those? Maybe it does, I'm not sure.)

nuget doesn't recognize installed packages

I have a C# project on Git that uses libraries from NuGet. Everything works fine, but when I pull on a fresh new machine and open the solution in Visual Studio it won't compile because of broken references. If I click on the references under the project I can see the classic warning sign with the yellow exclamation mark.
Nuget restore won't do anything (and I still haven't found any use of this feature...), files repositories.config are fine. If I right click on solution and then 'Manage NuGet packages for solution' no installed package is shown.
To this day I solved it this way: run
Install-Package package_name
it says:
'package_name' already installed.
My_project already has a reference to 'package_name'.
...and after that it shows the packages on the Manager, already assigned to the correct project.
NOTHING HAS BEEN CHANGED in the code ANYWHERE, I can see that because there are no differences on Git.
I have to do it only once on new machines, but it's really annoying. Any idea?
NuGet version: 2.8.60318.667
UPDATE 27/07
I tried the procedure from scratch on another PC, with windows 10, and everything works... same version of Visual Studio, NuGet, etc... I'm baffled
This is probably because of the incorrect path of the .dll in your .csproj. The package restore downloads the packages to the local directory. It doesn't change the reference path of the assembly in the .csproj, meaning that the project will still try to locate dlls on the local directory. The yellow mark means the project is unable to locate the assembly.
Unload the project, right click on project and select "Edit .csproj", and verify the path of missing dlls. For example - If you have NUnit,
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
verify if the dll is present inside "\packages\NUnit.3.6.1\lib\net45" directory.
From the top of my head I can think of a few reasons the packages are not being downloaded, ideally you would have to share a few more details.
First the install-package command won't work. Your packages are already installed VS is just unable to download them, so it makes sense that you are getting that error.
First and foremost is this a public package hosted in nuget.org like
System.MVC.Web? Because if this is in a new machine, using a private nuget server, you need to
configure that source in Tools > Options > Nuget Package Manager >
Package Sources. (See https://learn.microsoft.com/en-us/nuget/tools/package-manager-ui for more details)
Check if you have added the folders to your git repo but at the same
time set the exclusion for its contents. To check that when you do a
clean checkout see if the folders exist but are empty. If thats the
case just remove the folders, the git ignore should do its job from
now on, and everyone new clone will do the proper check.
If the two above which are the most likely ones to be the reason do
not work. Try and restore the packages from the Package Manager
Console and update your post with the details.
You can open the Package Manager Console and type:
Update-Package -reinstall
or
Update-Package -reinstall -Project YourProjectName
FYI there's comprehensive document from Microsoft - https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore - on the multiple ways of restoring nuget packages
try removing your package from below nuget cache folder so that NUGET is forced to download from source
C:\Users\<< your user name >>\.nuget\packages
I experienced this issue today, and upgrading to the latest version of VS 2017 (15.8.7) didn't help at all.
Check your packages.config file(s) to see if your packages tag looks like this:
<packages xmlns="urn:packages">
If it does, remove the xmlns attribute so it's just:
<packages>
That fixed it for me!
I have solved this problem. Follow this steps
In Visual Studio, click Tools > Extension and Updates.
Navigate to Online, search for "NuGet Package Manager for Visual
Studio" and click Update.
(If there is no button Update, navigate to Updates > Visual
Studio Gallery, find the "NuGet Package Manager for Visual
Studio" and click Update.)
Then restart Visual Studio.
Even after you've installed it at the Solution level, depending on your default you may have to pick which projects you want it to be available in. That was my problem.

How Do I Make the Builder on Visual Studio Online Restore All NuGet Packages?

I have a solution in Visual Studio 2015 that uses several NuGet packages. When I build in Visual Studio 2015, the packages are restored properly and the build succeeds. However, when I push that same project to Visual Studio Online, even though I have "Restore NuGet Packages" checked, the build fails because MSBuild cannot find the referenced binary.
I have looked at the build log and see that my packages are all being restored. Why, even though the package is restored, is the referenced binary not found during the build?
I found that the problem was not in the NuGet package restore, but in the way that the hint path was written in my .csproj file. To the fix the problem, change the hint path to point to the solution directory using the $(SolutionDir) variable.
For example, the NuGet restore pulled the Microsoft.WindowsAzure.Storage.dll binary, but it could not be found on the build of the project. To fix this, I had to open the .csproj, find the reference to the dll, and change the path from
..\packages\WindowsAzure.Storage.6.1.0\lib\net40\Microsoft.WindowsAzure.Storage.dll
-- to --
$(SolutionDir)\packages\WindowsAzure.Storage.6.1.0\lib\net40\Microsoft.WindowsAzure.Storage.dll
By using the $(SolutionDir) variable, Visual Studio Team Services was able to find my referenced dll and build my project properly.
You might also consider checking if the file packages.config, which surely resides on you local system, also gets checked in and is under version control.
First, you might want to see if it's present at the build server (image below is from VS Team Services but it's the same general idea in on-site environment.
Secondly, verify that the file's under version control. As a test, see if it appears under Pending Changes if you add a package.
I made a project with a working build start to fail when I added nUnit. Then, as I checked in the package.config file, it started to restore the packages on the server. When I removed the file from the server, the builds starter to fail again. Details are described in this post.

Solution doesnt run/build/rebuild in Visual Studio

When trying to run Build / Rebuild in Visual Studio on a solution, nothing happens.
I can run the build from the command prompt using MSbuild.exe, and this gives me the output i would expect (Build succeeded) - But when trying to run it from visual studio, nothing happens. Theres no debug output or build output either.
The project is a MVC project, with some references to other projects.
I can create a new MVC project, and it runs just fine!
Any idea what might trigger this behavior?
Using Visual Studio 2015.
I Have tried the following:
Restarting VS
Comparing the solution file to a new solution file
Triggering build manually from MSBuild (OK)
Switching Debug / Release configuration
Building projects individually
Updated NuGet
Build Configuration is OK (Everything checked for Build)
That beeing said, the solution is inside a git repository, and the other person working on this project has entered at a later stage with Visual Studio 2013 - But i dont know if this has anything to do with the issue.
Go to your configuration Manager and make sure build checkbox is selected for your project.
other thing you can try is:
Go to tools > Options>> A window will pop up> Under Project and Solutions > select Build and Run
Make sure Before building is set to Save all changes
So what seemed to happen was that there was some kind of dependency on a separate git repository (bootstrap), in our private repo that i hadnt been getting access too - so instead of giving me an error about it it just silently failed.
Adding access to the repository to my account, suddenly made the project run again.
Try this:
Go to Tools -> Options -> Projects and Solutions -> Web Package Management
Under that UNCHECK option "$(VSINSTALLDIR)\Web\External".
After UNCHECKING the "$(VSINSTALLDIR)\Web\External" option, Restart Visual Studio and try to rebuild project.
Check whether any NuGet packages are missing, that was the problem with me. Go to
Tools -> NuGet Package Manager -> Package Manager Console
If any packages are missing, Visual Studio will show you a message and a "Restore" button to fix the problem. After that the application should build.

Categories