How to change a nuget packet assembly version - c#

In Visual Studio with my Asp.net core project, I have used some nuget packets (like StackExchange.Redis, Serilog etc..). I decided to use Visual studio 2019. Everything was going well, but one day I noticed some projects couldn't update their referenced projects in solution. Because they are (.net standard libraries) taking output codes to obj folder instead bin folder.
I decided to return Visual Studio 2017. Everything working great with VS2017, but this time it giving me a run time error such as could not found referenced assembly public key etc.. like below
I have removed old pockets from all projects in the solution by the package manager nuget manager. I have installed a new version by the nuget manager tool. But project always seemto be using the old version.
FileNotFoundException: Could not load file or assembly 'StackExchange.Redis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46'. The system cannot find the file specified.
For example, if I install a nuget packet version 2.0.0.0 and I want to remove it all from project and I want to install a new version by an upgrade or downgrade. What should I do? How can I change it?
Update: I have uninstalled 2 packages from nuget and from windows, still project seen this assemblies!
Severity Code Description Project File Line Suppression State
Error CS0433 The type 'ConnectionMultiplexer' exists in both
'StackExchange.Redis.StrongName, Version=1.2.6.0, Culture=neutral,
PublicKeyToken=c219ff1ca8c2ce46' and 'StackExchange.Redis,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=c219ff1ca8c2ce46' Tursys.Pool.Storage.Api D:\projects\tursys\PoolStorage\src\Tursys.Pool.Storage.Api\Startup.cs 76 Active
Both of them not exist

You can try it:
Install-Package "YourProjectName" -Version 6.2.0

Answering my own question, for anyone:
VS-2019 corrected it's output folder as bin folder with a new bug-fix! but it was not related with the nuget package removement problem
How to remove a package from a project:
In Visual Studio i want to go to file with F12 key. And with the open target folder command i see the local folder of the removed package as
C:\Users\HAMIT\AppData\Local\Temp\MetadataAsSource\821e7bd605414042826501fe0b5cdc21\32ae5450ea724e84b62f983bdb6bb879
I have deleted this temp files but by the rebuild process VS restored them again. This some bored me and i found a new manner. There is always a technic to removing a package from the VisualStudio with the -force argument like below in PM Console
Uninstall-Package -ProjectName "YourProjectName" -RemoveDependencies -Force
When you put this command it will asking you the PackageId will be removed. Write your package name and it is ok!
If you dont know your package name exactly then you can get a list according your project like below:
Get-Package -ProjectName "YourProjectName"
But uninstalling to StackExchange.Redis.StrongName still is enigma!!!
UPDATE: I found a solution for this too! Change Aspnetcore framework 2.2 to 3.0 under Visual Studio 2019. Now seem to right dlls and Everything corrected.

Related

error CS0234: The type or namespace name 'OAuth' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?)

I am trying to build a project with cli:
msbuild.exe project.sln
I get errors of this type:
App_Start\NinjectConfig.cs(3,31): error CS0234: The type or namespace name 'OAuth' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?) [path_to_file\file.csproj]
I tried nuget restor
Also I have in root directory of my project folder for packges in which you have packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45 with Microsoft.Owin.Security.OAuth.dll file.
In file.csproj I have a reference:
<Reference Include="Microsoft.Owin.Security.OAuth">
<HintPath>..\..\packages\Microsoft.Owin.Security.OAuth.2.1.0\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
I can see the differences in versions, but there are 2 questions:
1) why visual studio is building this with no errors? How come it works with vs but not with cli?
2) Why is nuget installing wrong version?
3) How can I export from vs a config for nuget to install all packages?
I am a newbie - so be gentle please.
1) why visual studio is building this with no errors? How come it works with vs but not with cli?
Since we do not have your project/solution, we could not figure out the reason why the Visual Studio is building with no error. But if you resolve your latter two problems, you will not be confused about this problem.
2) Why is nuget installing wrong version?
NuGet not install the project to the project file when you use the nuget restore command line. This command line just Downloads and installs any packages missing from the packages folder, So it not change the nuget package version in the file.csproj when you use that command line, it just download the package Microsoft.Owin.Security.OAuth.3.0.1 and set it to the \packages folder based on the nuget.config file, it will not check the HintPath in the project file. That is also the reason why you can see the nuget package in root directory of your project folder.
However, the path and version is not correct in the file.csproj(Could not know the reason, may be accidentally changed manually or for other reasons), it should be:
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
Single ..\ and version is 3.0.1.
So, to resolve this issue, we should re-install the nuget package instead of restore it. You can uninstall it and reinstall that packages.
3) How can I export from vs a config for nuget to install all packages?
There is a packages.config file in your project, you can install the all the packages with Package Manager Console in Visual Studio, but you could not install all the packages with nuget CLI. Because package manager console is providing is access to visual studio objects.
Check another thread for some more details.
Hope this helps.

Could not load file or assembly 'System.Security.Principal.Windows'

Solution has compiled successfully, but after I added an existing class file to the project, this error appeared:
The specified task executable "csc.exe" could not be run. Could not
load file or assembly 'System.Security.Principal.Windows,
Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file
specified. MvcApplicationRegister
I installed System.Security.Principal.Windows package By NuGet, but error still appears.
None of the previous answers worked for me.
The problem was that I didn't have the .NET Compiler Platform SDK installed.
To solve, open Visual Studio Installer, choose "Modify", and under the "Invididual Component" tab, check the .NET Compiler Platform SDK, and confirm your changes by clicking "Modify".
After I installed it and reopened Visual Studio, the problem is gone.
I had the same issue after I upgraded Microsoft.Net.Compiler from 2.8.2 to 2.9.0.
After I downgraded to 2.8.2 projects compiled without any errors.
Had this same issue and resolved it.
In a 3 project solution MVC controller (Web,Business,Data)
Caused by the Microsoft.Net.Compiler 2.9.0 being installed on the Web project but not the other projects.
To resolve:
Right click the solution.
Manage NuGet Packages.
Installed > Search for the compiler
Ensure it is the same version and it is installed on all projects in your solution
Once installed my solution built successfully
If you are using Microsoft.CodeDom.Providers.DotNetCompilerPlatform you can upgrade to 2.x and then remove Microsoft.Net.Compilers as it's no longer needed. That solved it for me, however I couldn't even build the solution in the first place. It was still complaining about System.Security.Principal.Windows though, I could also solve it by referencing System.Security as an assembly. It's not recommended though.
Close down all instances of Visual Studio. Then reopen the solution and rebuild.
I uninstalled both Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers and everything now works.
In my case I could go from Microsoft.Net.Compilers 2.4.0 to Microsoft.Net.Compilers 2.10.0. No need to use Microsoft.Net.Compilers 2.8.2.
I do not like removing packages without first understanding what I'm removing. I faced the same problem with my solution.
I discovered that 1 of the many projects was using the Microsoft.Net.Compilers NuGet package - let's call it Project ABC. A Unit Test project was referencing that Project ABC, but not the Microsoft.Net.Compilers NuGet package.
I simply referenced the Microsoft.Net.Compilers NuGet package from my Unit Test project, and the problem has now gone away.
Updating Microsoft.CodeDom.Providers.DotNetCompilerPlatform and deleting Microsoft.Net.Compilers worked for me.
I had the same issue here using 'System.Security.Principal.Windows' version 4.7.0. For some reason when I installed the nuget package it was referecing the dll from the folder: C:\Users\{your-user}\.nuget\packages\system.security.principal.windows\4.7.0\ref\netstandard2.0\System.Security.Principal.Windows.dll then I changed to reference the dll from the folder C:\Users\{your-user}\.nuget\packages\system.security.principal.windows\4.7.0\lib\netstandard2.0\System.Security.Principal.Windows.dll and everything worked just fine! So I copied the dll from the lib folder to my project and made a direct reference.

'System.Web.Mvc.VirtualPathProviderViewEngine' is defined in an assembly that is not referenced

The complete error is "'System.Web.Mvc.VirtualPathProviderViewEngine' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'"
I have an Asp.Net Mvc 4 application build in Visual Studio 2010 that does not build on one machine but builds on another machine without issue. Through the tips System.web.mvc missing I discoverd that the machine that builds does indeed have MVC 3 version 3.0.50813.0 and the machine that does not build has MVC 3 version 3.0.20105.0 so I uninstalled MVC 4 and MVC 3 and attempted every combination of uninstall and reinstall between downloaded installers and the web platform installer but the problem machine still gets the older version. I decide that I will just attempt to fix the project by upgrading the NuGet package for the one project using the suggestion from the question
Install-Package Microsoft.AspNet.Mvc -Version 3.0.50813.1
at which point it the following error with the NuGet package Manager
"Install-Package : The schema version of 'Microsoft.AspNet.Mvc' is incompatible with version 2.0.30625.9003 of NuGet. Please upgrade NuGet to the latest version" In attempting to fix that I find this Nuget versioning issue with package restore
I performed the answer from there and got the same error when attempting to install the NuGet package, which makes sense because it is looking for an older version of NuGet.
I also looked at this MS14-059 but my project does not even reference the MVC 3 dll so the manual update option is out and I have tried the NuGet package.
My question is
Does anyone know where I can find an installation of the MVC 3 framework for version 3.0.50813.0
OR
How I can get the NuGet package to install in my solution.

Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependenc

An update occurred last night and now I find myself unable to do a ctrl + '.' for code suggestions in VS 2015. An error message comes up saying the following:
Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I can still build and develop but this will be really annoying without this feature. I admit it, I am getting soft!
Anyone have a suggestion for fixing this bug?
As pointed out by #CaptainAmerica the solution is to update the CodeDom assembly from NuGet. One should point out how to do this in Visual Studio.
I found the solution here:
https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/
Basically, in the Visual Studio menu select:
Tools-> Nuget Package Manager -> Package Manager Console
In the console that appears at the bottom of Visual Studio run this command:
Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
If any of the options doesn't work, here is the detailed guide to handle this scenario....
First of all version is important. Notice the version mentioned in the error...
Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
If you see above error it means that it's not able to find version 1.3.1. Now please create new VS project. No preferences, it can be just simple console application. Now once project template is ready, go to Package Manager and run following command with your specified version...
Install-Package Microsoft.CodeAnalysis -Version 1.3.1
This will install all packages. Let it complete. Once it's done. We don't need this newly created project at all. You can delete it completely. Seriously! you can delete it. We did this because we wanted that package installed at global nuget level. When you install something, nuget stores it at global level of your machine as well. Path will be something like this...
C:\Users\<<Your Windows User>>\.nuget\packages
You can know your path by following...
%USERPROFILE%\.nuget\packages
Now you will see your required Microsoft.CodeAnalysis.dll there in following folder...
C:\Users\<<Your Windows User>>\.nuget\packages\Microsoft.CodeAnalysis.Common\1.3.1\lib\net45
Please note that above path contains version number (1.3.1). If your version is different, look into that version folder.
Now that you have dll with you, all that you need to do is add that dll to GAC. For that you will need GacUtil.exe
This file get installed along with Visual Studio already. You can search "GacUtil" in C drive. For me it's there on below path...
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools
Now run command prompt as Administrator and navigate current directory to your path containing GacUtil. The run below command to install that dll in GAC.
gacutil
-i C:\Users\<<You Windows User>>\.nuget\packages\Microsoft.CodeAnalysis.Common\1.3.1\lib\net45\Mi
crosoft.CodeAnalysis.dll
Basically providing path to dll we installed globally. It will show message on successful installation.
That's all! Now start your Visual Studio again and you will get this issue fixed.
I had the same problem with Visual Studio 2015 Update 2, to solve the problem globally for all solutions, update to Visual Studio 2015 Update 3. Here is a link: Download from here
I found this page and at the bottom of the page under "Compatibility with ASP.NET" it says that ASP.NET uses the nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform to update the Microsoft.CodeAnalysis assemblies. So I updated the DotNetCompilerPlatform package from 1.0.0 to 1.0.3 and it works again! Yeah, life is good again!
To solve this problem for all solutions, I needed to install the assembly Microsoft.CodeAnalysis.dll directly to the GAC – Global Assemblies Cache.
I got the file Microsoft.CodeAnalysis.dll from C:/Users/[user]/.nuget/packages/Microsoft.CodeAnalysis.Common/1.3.2/lib/portable-net45+win8/Microsoft.CodeAnalysis.dll.
To install the assembly to the GAC, I used a PowerShell script from https://github.com/LTruijens/powershell-gac.
Finally, I managed to install the assembly to the GAC with the following command from PowerShell:
Add-GacAssembly [myPath]\Microsoft.CodeAnalysis.dll
I was also facing same issue. My visual studio 2015 version was 2.0. I upgraded it to version 3.
Issue got solved !!!
I was also facing same issue, Try installing Microsoft.CodeAnalysis.CSharp nuget package. And if its not resolved, check version of Microsoft.Net.Compilers in your project, I was having version as 1.0.0 which was causing issue so updated Microsoft.Net.Compilers nuget to v1.3.2.
Found solution here : Github discussion
I have solved the problem this way:
Update Visual studio 2015 to Update 3
from the menu chose View => Notifications => Visual Studio Update 3 and clicked the update button.
Today ! i got the same problem and i resolve it by restarting visual studio 2015 :)
I encountered this issue when trying to build someone's code from github.
I was opening it in VS 2019 but I also have VS 2022. Opening and building in VS 2022 just worked.
I fixed this issue by updating all Nuget Microsoft dependencies to v2.0.0. This was using VS 2017. I was using a preview version.
In my case, the error occurred after turning off Live Unit Testing and running tests manually.Some tests would fail with the above error message.
Going into Test --> Live Unit Testing --> Options and issuing "Delete Persisted Data" resolved the problem.
I fixed similar issue by deleting the .vs folder located inside the solution.
I found the missing assemblies in the NuGet package (After the first one was resolved there were mulitple otheres): https://www.nuget.org/packages/Microsoft.Net.Compilers/1.3.1-rc
Installed them using GacUtil from the Dev console.
Unfortunately the extensive solution with "nuget install/gacutil" here above couldn't work as the exact version of the dependency dll was not available.
The following solved my issue in our complex webform application was to perform within the solution in Visual Studio -> Tools -> Nuget -> console package manager
Update-Package -reinstall
In my case, I was getting this error because my Visual Studio Solution was trying to use TextTransform.exe during a pre-build step in one of the projects, but my local machine didn't have the TextTransform.exe at the path specified by my pre-build step and my first attempt at fixing that was to just copy TextTransform.exe from some other location to where Visual Studio expected it to be. That appears to have caused this problem, because TextTransform.exe has other silent dependencies.
My fix was to change the pre-build steps so instead of looking for the file at
C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe
it would instead look in the Visual Studio install folder which had a bunch of other files, presumably one of which was a peer dependency of TextTransform.exe
C:\Program Files\Visual Studio\Common7\IDE\TextTransform.exe
That seemed to fix things for me.
I got the same problem, I am using VS2017 and installed Microsoft.EntityFrameworkCore.SqlServer 3.1.8, while in my VS2017 .Net core version is 2.1
So I downgraded my Microsoft.EntityFrameworkCore.SqlServer to 2.1.1 and restarted the solution.
The warning was gone !!
I had similar errors in VS2019 after upgrading project to .Net 5 according to https://learn.microsoft.com/en-us/aspnet/core/migration/31-to-50?view=aspnetcore-5.0&tabs=visual-studio.
error CS0006: Metadata file
'C:\Users\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll'
could not be found.
'C:\Users\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll' could not be founderror CS0006: Metadata file
The fix was to close and reopen VS 2019
Try adding Nuget Package Microsoft.VisualStudio.Web.CodeGeneration.Design to your project
This question is many years old and the answers are all fairly old as well. I only recently ran into a similar-enough issue that I feel sharing my experience here (although potentially not complete) is relevant.
D:\Code\C#\sdkrazortest>dotnet --version
6.0.401
D:\Code\C#\sdkrazortest>dotnet new webapp -o webapp1
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/6.0-third-party-notices for details.
Processing post-creation actions...
Running 'dotnet restore' on D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj...
Determining projects to restore...
Restored D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj (in 102 ms).
Restore succeeded.
D:\Code\C#\sdkrazortest>cd webapp1
D:\Code\C#\sdkrazortest\webapp1>dotnet build
MSBuild version 17.3.1+2badb37d1 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
REWRITECSS : error : [D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj]
An assembly specified in the application dependencies manifest (rzc.deps.json) was not found:
package: 'Microsoft.CodeAnalysis.Common', version: '4.3.0-3.22415.1'
path: 'lib/netcoreapp3.1/Microsoft.CodeAnalysis.dll'
Build FAILED.
REWRITECSS : error : [D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:10.32
I originally tried loading packages like the top comments here had suggested and realized this issue started happening shortly after install .net core 6. After seeing some SO comments on dotnet-aspnet-codegenerator being version-specific I tried to create my netcore3.1 app using an older version of the dotnet cli via global.json:
D:\Code\C#\sdkrazortest>type global.json
{
"sdk": {
"version": "3.1.403"
}
}
D:\Code\C#\sdkrazortest>dotnet new webapp -o webapp2
Getting ready...
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/3.1-third-party-notices for details.
Processing post-creation actions...
Running 'dotnet restore' on webapp2\webapp2.csproj...
Determining projects to restore...
Restored D:\Code\C#\sdkrazortest\webapp2\webapp2.csproj (in 187 ms).
Restore succeeded.
D:\Code\C#\sdkrazortest>cd webapp2
D:\Code\C#\sdkrazortest\webapp2>dotnet build
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
webapp2 -> D:\Code\C#\sdkrazortest\webapp2\bin\Debug\netcoreapp3.1\webapp2.dll
webapp2 -> D:\Code\C#\sdkrazortest\webapp2\bin\Debug\netcoreapp3.1\webapp2.Views.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:09.91
While this isn't an answer for the new templates not just working for me.. it might help someone potentially get "unstuck" or be the catalyst for someone providing a proper answer.
You need to install NuGet package Microsoft.Net.Compilers.Toolset, but make sure you match the right .NET version. In my case I was targeting netcoreapp3.1 so max version could be 4.0.1.
My root cause was for MassTransit analyzers nagging they cant find Microsoft.CodeAnalysis package, eg. An instance of analyzer MassTransit.Analyzers.AsyncMethodAnalyzer cannot be created.
I think one of the possible reasons for this issue could be the incompatibility of the .NET Framework and certain NuGet package. In my case I have .NET Core 3.1 and Testcontainers 2.4.0. The error does not happen on my local machine but it keeps showing up in my GitHub Actions remotely. It goes away after I downgrade Testcontainers to 2.3.0. Later the NuGet package AspNetCore.HealthChecks.EventStore 6.0.2 causes the same issue but that gets fixed in minutes rather than in hours :)

Nuget Packages are missing in Visual Studio

I have been using xamarin studio, it works fine when I download a sample project from mvvmcross. It compiles and deploys the device perfectly.
But when I open the project in the visual studio, there are a lot of missing packages for some reasons. Is there a way of handling ? I am using Nuget 2.8 in Visual studio 2013
When I open Nuget as follows, there is a button to restore the missing packages. I clicked on it.
Then it is attempting to download the missing packages, and then it realizes there are dependencies as follows:
Then I am attempting to download the dependency manually as follows but it shows the packages has already downloaded but I am still seeing the missing packages in the solution, nothing is affected.
Therefore I am getting hundreds of errors as follows:
When I take a look at the property of missing packages, I see as follows
You should update your NuGet Package Manager extension in Visual Studio and then try restoring the packages again.
The restore error MvvmCross.Binding already has a dependency defined for MvvmCross.Core is caused by an old version of the NuGet package manager extension not recognising the newer target frameworks that the MvvmCross.Binding NuGet package is using in its group dependencies. This bug has been fixed in a newer version of the NuGet Package Manager.
If you search for the 'already has a dependency defined' error message you will find several cases of this, such as this StackOverflow question, for example:
Can not install NuGet package
Right click on the solution in solution explorer and choose 'restore nuget packages'

Categories