Visual studio 2019: Adding, Updating or Deleting Package Source Has No Effect - visual-studio

I had a package source named MyMyGetFeed, I changed its URL but it still looking at the old one, even after deleting it I can still see that visual studio is looking into it as shown in the error message below, I'd also tried to create new package source with the new URL and it is still showing the same error neglegting my new source. Cleaning project, restarting Visual Studio and even deleting NuGet.Config file didn't help. Any Ideas please?
Severity Code Description Project File Line Suppression State
Error NU1102 Unable to find package Synergix.WE.Security.Cryptography with version (>= 2.1.3)
- Found 3 version(s) in MyMyGetFeed [ Nearest version: 2.1.2 ]
- Found 0 version(s) in nuget.org Synergix.ADCE.Client.Service.Commands C:\Users\MOHAMMAD\source\repos\adce.client\src\Service\Synergix.ADCE.Client.Service.Commands\Synergix.ADCE.Client.Service.Commands.csproj 1

Visual studio 2019: Adding, Updating or Deleting Package Source Has No
Effect
First, if you add the new package source by Tools-->Options-->Nuget Package Manager-->Package Sources(global nuget.config file), you should make sure that there is no other custom nuget.config in your solution explorer to affect the global nuget.config file. See this.
Besides, you can follow the below steps to troubleshoot your issue:
you should make sure that the new package source url is enable and the old package source url is deleted or unchecked like this:
In global nuget.config file(C:\Users\<User>\AppData\Roaming\NuGet\) like this:
<packageSources>
<add key="new package source" value="C:\xxxxxx" />
<add key="old package source" value="C:\xxxxxxx" />
</packageSources>
<disabledPackageSources>
<add key="old package source" value="true" />
</disabledPackageSources>
From the error message, it searches for version 2.1.3, so make sure that Synergix.WE.Security.Cryptography 2.1.3 is in the new package source url and you have the right to access the new package source. To test it, you can copy the link in website to see whether it can return any request.
clean nuget caches under Tools-->Options-->Nuget Package Manager-->General-->Clear All Nuget Caches or just delete the packages folder under C:\Users\xxxx\.nuget.
And run nuget locals all -clear under Tools-->Nuget Package Manager-->Package Manager Console
disable any third party extensions under Extensions-->Manage Extensions in case it causes this abnormal behavior.
close VS instance, delete .vs hidden folder, bin, obj folder, 'Nuget.Config' file under C:\Users\<User>\AppData\Roaming\NuGet\(will recreate automatically when restart VS)
and then run VS as administrator to test whether the issue persists.
In addition, try to create a new default project and then install this package to test whether the issue is your project itself or is the nuget tool.

Related

How to change the NuGet-package reference in a Visual Studio project to use Nuget.config

I have a Visual Studio project file with the extension .csproj. Inside it are references like this:
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props"....
I have now made a NuGet.config file in the parent folder of from the solution folder. And I removed the local "packages" folder. In the new nuget.config I set up a common location for storing packages.
nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="D:\Data\NuGet" />
</config>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
</configuration>
When I building I now get this error:
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information...
The missing file is ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.
How can I solve this?
If I manually have to replace the (Import Project="..\packages...) elements in the project file, what should I change it to, so that it follows the configuration from the Nuget.config?
If I manually have to replace the (Import Project="..\packages...)
elements in the project file, what should I change it to, so that it
follows the configuration from the Nuget.config?
Since you use the new nuget.config file which changed the path of the local nuget reference(like this <add key="repositoryPath" value="xxxxxx" />).
And Restore will only restore the missing nuget packages but will not change to use the new nuget package location in xxx.csproj.
So you can follow my steps to resolve the issue:
Solution
1) Tools-->Nuget Package Manager-->Package Manager Console-->
type Update-Package -reinstall to reinstall these packages to reference the new right path.
2) enter the xxxx.csproj file, delete these duplicate, old import info like these:
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\..\..\..\..\installed_packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
3) Then rebuild your project and will solve this issue.
Update 1
The new Nuget.config file will specify that the newly installed nuget packages use the new reference address, but for previously installed nuget packages, the reference address in the xxx.csporj file will remain the old address. The Restore procedure only restores the nuget package under the new path, but it does not make any changes to the nuget reference in xxx.csproj file, so it can only be reinstalled.
Besides, the import node is created by Microsoft.Net.Compilers props file from the build folder in the microsoft.net.compilersnuget package. And it is a nuget mechanism which can do some operation in xxx.csproj file when you install the nuget package.
However, this file is also special and when you change the nuget reference path.
Because nuget enabled the new address mechanism, during the uninstallation process, the old address of Microsoft.Net.Compilers.props is still not recognized, so it cannot be uninstalled. In fact, when you execute the reinstall nuget package, a new address has been created in the xxx.csproj file. See this:
So you should just delete duplicate files from the old address.
Visual Studio option to change the Nuget Package References
In Visual Studio Tools=> Nuget Package Manager => Package Sources.
You can change the package sources here.

How to disable "transitive package management" for a Visual Studio project

How do I disable "transitive package management"?
I wish to do so, so that I can install a package that I "packed" locally and have in a .nupkg file. When I attempt to do so, I get a messaging stating that The 'Source' parameter is not respected for the transitive package management based project(s) {csproj file}. The enabled sources in your NuGet configuration will be used.
Complete Context
When developing a NuGet package that's not ready for distribution via our NuGet feed, I often create a local .nupkg file like this from the package manager console:
nuget pack {path-to-csproj-file}
This generates a {project-name}.nupkg file, which I can then install in another project by opening it in Visual Studio, navigating to the package manager console, and entering the command
Install-Package {path-to-nupkg-file}
This has worked great and once the NuGet package is ready for distribution, we push it up to Azure DevOps and let the build pipeline there push it into our feed.
However, I just recently inherited a project where the prior developer apparently setup "transitive package management" that prevents this workflow. Here's what I get when I try to install directly from a .nupkg file:
Install-Package C:\Users\Josh\source\repos\SpeakerDiscountManager\SpeakerDiscountData.1.0.5.nupkg
The 'Source' parameter is not respected for the transitive package management based project(s) MembershipApplicationWidget\MembershipApplicationWidget.csproj. The enabled sources in your NuGet configuration will be used.
<snipped several lines of unsuccessfully searching configured package sources>
Install-Package : NU1102: Unable to find package SpeakerDiscountData with version (>= 1.0.5)
Obviously, it doesn't find the package I've specified via file, because it is searching online feeds and it doesn't exist in any of our online package sources--the package is in a testing state, not ready for anyone to use but me.
Based on the error message, I need to turn off "transitive package management" so that I can specify a file source for the package, but I've been unable to turn up any information online about how this is configured.
I did try installing this exact same .nupkg file in another project, using the same Install-Package {path-to-nupkg-file} procedure. This works.
How to disable “transitive package management” for a Visual Studio
project
I think this problem transitive package management is related to your current project structure which has some intricate dependencies, custom rules and so on. Therefore, turning off transitive package management is unpractical. If you create other projects and then install this package by your way, I think it probably will not occur.
As a best workaround, as you said(hint from the message The enabled sources in your NuGet configuration will be used.), add the the local nuget package's path into Nuget Package Source.
In your side, I think you specify -Source xxxxx(the path of the nuget package) to install this package in the package manager console, if so, this function actually is inconvenient.
You can just add the folder path which SpeakerDiscountData.1.0.5.nupkg exists into global nuget package source. Once you have done it, it will applies to any projects in this machine.
It has two ways:
1) VS IDE UI
Tools-->Options-->NuGet Package Manager-->Packages Sources-->add a new key and input the path of the nuget folder. Also, check its option.
2) global NuGet.Config file
(C:\Users\xxxx\AppData\Roaming\NuGet\Nuget.Config and step 1 is just add the path into this file by VS UI Control)
add these:
<packageSources>
<add key="Local Packages Source" value="C:\Users\Josh\source\repos\SpeakerDiscountManager\" />
..........
</packageSources>
After that, you can use your command to install this nuget package.
Note: If the root directory of your solution also has a file named nuget.config, the parameters in it will override the global file. It has the highest priority.
Just go to Vs IDE Tools/Nuget Package Manager/Package Manager Setting And Check The address of Package Sources.
it's something like "C:\Program Files (x86)\Microsoft SDKs\NuGetPackages".
Then Copy your package file into that folder and at last run this command in Package Manager Console:
install-package packagename

how to fix ChakraCore NuGet package error?

When initializing a new React Native Windows WPF project, this error happens:
NuGet Package restore failed for project Native: Unable to find version '1.4.1-preview-00010-42060' of package 'Microsoft.ChakraCore'.
https://www.myget.org/F/chakracore-preview/api/v3/index.json: Package 'Microsoft.ChakraCore.1.4.1-preview-00010-42060' is not found on source 'https://www.myget.org/F/chakracore-preview/api/v3/index.json'.
https://api.nuget.org/v3/index.json: Package 'Microsoft.ChakraCore.1.4.1-preview-00010-42060' is not found on source 'https://api.nuget.org/v3/index.json'.
If I create a standalone project and add the same NuGet package reference, I get the same error -- even on Xamarin Studio Mac.
The problem is that the project was referencing the "preview" feed on myget.org, instead of the official release feed on nuget.org. In the NuGet.Config file(s) in your project, remove line that references the preview feed that looks like this:
<add key="ChakraCore" value="https://www.myget.org/F/chakracore-preview/api/v3/index.json" />
In the Visual Studio 2015 (or Xamarin/Visual Studio Mac) project, right-click on the project and select Manage NuGet References. From there, you can click on the Updates tab, select ChakraCore from the list, and click "Update". This should update the packages.config and other files for you. Note that if you had the project open while editing the config files you'll need to close and re-open the project to get the new settings to take hold. In some cases, the upgrade may leave behind the reference to the previous 1.4.1-preview package and you'll need to hand-edit the csproj file to get rid of it.
If you need to make this change without Visual/Xamarin Studio, you just have to edit a few text files. In the packages.config (in Visual Studio 2015), change the line referencing the 1.4.1-preview version to the latest release (1.5.2 as of this writing):
<package id="Microsoft.ChakraCore" version="1.4.1-preview-00010-42060" targetFramework="net46" developmentDependency="true" />
becomes
<package id="Microsoft.ChakraCore" version="1.5.2" targetFramework="net46" developmentDependency="true" />
In your project's csproj file:
<Import Project="$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" />
becomes
<Import Project="$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props')" />
and
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
becomes
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
Generally speaking, don't reference preview packages from myget.org in production projects or project templates others will use. They can be removed at any time, and security updates may not be published there with the same regularity as official channels.
Looks like the preview Microsoft.ChakraCore NuGet package was removed from the MyGet feed.
The main NuGet.org site only has stable releases for the Microsoft.ChakraCore NuGet package.
So you are left with editing any references to the package and using a published version. Microsoft.ChakraCore version 1.4.4 should work.
There is also an open issue about this on the React native GitHub site.

Task for a Bamboo Build plan fails when trying to get information from packages

I am trying to run an MSBuild task in atlassian bamboo for a test run of a Bamboo plan on my local device. I have created the plan and it will retrieve the code from Github successfully, as well as being successfully running the default scoure control checkout.
The first problem I have is that the system will fail because the MSBuild task cannot get the referenced files. So when I looked into the Manage Nuget Packages, It says some of the packages are missing, and when I click Restore most of them restore but some of them have errors.
I think the main reason is because of this package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version 1.0.0 is not being installed correctly. The error message says that it is because the path, file name or both are too long, but I have not named anything the project is already build and running successfully from Github. I have tried to install as well by using the Package Manager Console but I get the same result. I also tried creating the folders that it said the file was meant to be located but this is not working either.
I think that the problem is that the package is not found during package restore so I tried to add a NuGet.config file.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>
But this is not working how can I fix this?
According to the error message screenshot, the mentioned package "Carfinance.Authorization.Core.Mvc" is not found in nuget.org site. Please make sure this package's source URL has added into your Visual Studio NuGet Package Manager Source list (Tools -> Options -> NuGet Package Manager -> Package sources).
And please add the node in the global NuGet.Config file which stored in C:\Users\UserName\AppData\Roaming\NuGet folder. After change the config file, please remember restarting your Visual Studio.
For the Microsoft.CodeDom.Providers.DotNetCompilerPlatform path too long issue, please make sure the stored path folder is not too long. You could create a new project and store it on desktop and install this packages to check whether it could be install correctly. Then please copy your current project on desktop too, it could make sure its stored path will not too long.

How can I fix missing nuget references after moving project in Visual Studio 2015

I had a project structure like this:
WebApp
-- WebApp
-- WebApp.sln
WebApp.Tests
-- WebApp.Tests.csproj
I moved WebApp.Tests into WebApp using a move (simple click & drag into the WebApp folder). I edited WebApp.sln to fix the project reference so that it will load.
When I build, Nuget complains that packages are missing and to do a restore.
I downloaded and used nuget.exe restore on my solution and it reported everything was there.
Based on other Stack Overflow answers, I have tried the following:
Edit the test project reference hint paths. I changed from ..\WebApp\packages\PACKAGE to ..\packages\PACKAGE
Reload Visual Studio (multiple times)
Delete contents of packages folder and bin/obj folders of the projects
Use the package manager console to reinstall packages on the Test Project
All of these failed to fix the problem. When I used the package manager to try to reinstall the packages with the command, it gave me the same error that project building does - I must restore the packages first.
Is there any quick way to fix my project? I really don't want to go through each package and uninstall/reinstall manually. Also, how could I have prevented this problem in the first place? Is there a built-in way to move project locations?
There was XML similar to this at the end of my project file:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\WebApp\packages\SPECIFICPACKAGE')" Text="$([System.String]::Format('$(ErrorText)', '..\WebApp\packages\SPECIFICPACKAGE'))" />
</Target>
By changing the ..\Webapp\packages to ..\packages like the rest of the file, my solution compiles just fine now.
I had the same issue where I physically moved a project folder into the src folder and got the missing packages error. My fix was to open up the .csproj file in notepad and replace every instance of
this:
..\packages\
with this:
..\..\packages\
It solved the issue...

Resources