Assembly dependency already defined error - c#

I'm having an issue when I try to build my project, I get this error:
'Newtonsoft.Json' already has a dependency defined for 'Microsoft.CSharp'
Everything I see about this says to update your nuget package manager, so I updated from VS 2015, to 2017 and that didn't work. I update VS2017 to the latest version, still getting that error when I try to build. I tried setting the build dialog verboisty to Diagnostic, but it did not change the text at all. What else can be causing this, because I'm stumped.
The error is accompanied by this error:
The command ""C:\Users\...\NuGet.exe" pack
"C:\Users\...\Project.csproj"
-Properties "Configuration=Debug;Platform=AnyCPU" -NonInteractive -OutputDirectory "C:\Users\...Debug" -symbols"
exited with code 1.
When I run the command manually in the command prompt, it just gives me the dependency already defined error.
EDIT
This was marked as a possible duplicate. It's not, the 3rd paragraph explains why.

Assembly dependency already defined error
You should update the nuget.exe version to 2.12 and above in the path "C:\Users\...\NuGet.exe".
According to the error message, that should be use old nuget.exe to pack the project with dependency netstandard.
As test, I used the old nuget.exe (2.8.6) to pack project with dependency Newtonsoft.Json 11.0.2 like your command line, I got the same error. To resolve this issue, you need to update the nuget.exe in the folder "C:\Users\...\NuGet.exe".
That is the reason why you already update the Visual Studio 2015 to 2017 and still have this issue, because you still use the old nuget.exe in the command line.
Hope this helps.

Related

C# Package not found on build even after installing

I installed the Newtonsoft.Json package through terminal on VS Code. On running the command "dotnet run" I get the error message:
"The type or namespace name 'Newtonsoft' could not be found"
together with other associated error messages.
How would I address this issue? Thanks
Try run dotnet build first then dotnet run.
The command depends on the dotnet build command to build the code.
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run?tabs=netcore30
Based on John's questions above, I found that my installation may have been faulty, so I used "dotnet add package Newtonsoft.Json" to install Newsoft.
Upon restarting VS Code, I found that the errors had disappeared. My sincerest thanks to everyone here in helping me solve this issue.

Ignore inaccessible sources w/ dotnet add package

When I try to add a NuGet package via the dotnet cli I get an error that it can't access one of my custom NuGet sources. Is there a way to say "I don't care, restore from where you can"?
McMaster.Extensions.CommandLineUtils clearly it exists in NuGet.org and it finds it but then stops b/c it can't access a custom source 🤷‍♂️.
PS c:\Temp\blah-project> dotnet add package McMaster.Extensions.CommandLineUtils
info : Adding PackageReference for package 'McMaster.Extensions.CommandLineUtils' into project 'c:\Temp\blah-project\blah-project.csproj'.
info : Restoring packages for c:\Temp\blah-project\blah-project.csproj
info : GET https://api.nuget.org/v3-flatcontainer/mcmaster.extensions.commandlineutils/index.json
info : OK https://api.nuget.org/v3-flatcontainer/mcmaster.extensions.commandlineutils/index.json 147ms
error: Unable to load the service index for source https://myinstace.pkgs.visualstudio.com/_packaging/Blah/nuget/v3/index.json.
error: Response status code does not indicate success: 401 (Unauthorized).
The dotnet command has the option to specify --source. This allows you to only restore packages from a specific location, in this case you'd want to use
dotnet restore --source https://api.nuget.org/v3/index.json`
This should pull the packages down to your local NuGet store and solve the problem on your machine.
In order to add the package to your project you may need to manually add a <PackageReference> to your project like
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.6.0" />
Then running the restore command above will get the package for you.
As a more-permanent fix, you should put a nuget.config file in the root of the project/repository where you specify the package sources for that specific project. There are settings that you can set to override your system's global nuget configuration/sources. See more information on nuget.config. You can create a starting nuget.config in your repo with dotnet new nugetconfig
while restoring packages, dotnet make a call to all the package sources to get the package and uses the one that responds first.
In your case, because of some authentication issue it is not able to access that source. That source can be disabled using the below command and then try to pull the package.
dotnet nuget disable source <NAME> [--configfile <FILE>]
You might be able use the --ignore-failed-sources option.
I'd recently encountered similar issues when having authentication problems on a private feed, this allowed me to install the packages (was actually a tool using dotnet tool install) and address my auth issue at a later date.
See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore for more info and options.

Run Microsoft Visual Studio C# project in Linux

I downloaded a c# .net project from git onto ubuntu and installed .net libraries from http://www.mono-project.com/download/#download-lin and also donet core from https://www.microsoft.com/net/core#linuxubuntu.
when I run donet restore, I am getting the following error
/home/ubuntu/DotNetWallet/src/DotNetWallet/DotNetWallet.xproj(8,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/1.0.3/Microsoft/VisualStudio/v14.0/DotNet/Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I guess the problem is with the DotNetWallet.xproj which generally is compatible with visual studio but how can I run it on ubuntu?
So, I
used 'dotnet migrate' ,and then used 'donet restore', it now works fine, but when I run 'donet build', I am getting the following error
FakeData.cs(1,20): error CS0234: The type or namespace name 'KeyManagement' does not exist in the namespace 'DotNetWallet' (are you missing an assembly reference?) [/home/ubuntu/DotNetWallet/src/DotNetWallet/DotNetWallet.csproj]
And, here is the git repo link https://github.com/nopara73/DotNetWallet
Many step are required in order to run this project.
First delete global.json file and then run dotnet migrate and remove the backup directory.
(Optional) In some case you will need to clean the solution. If DotNetWallet.xproj and project.json are still there, remove it and run the twxo following command.
dotnet sln remove src/DotNetWallet/DotNetWallet.xsproj
dotnet sln add src/DotNetWallet/DotNetWallet.csproj
Then, remove the first line (using DotNetWallet.KeyManagement;) from FakeData.cs file. This is an unused using statment. there are no impact to remove it.
Now, you can run dotnet restore, dotnet build then dotnet test.

Powershell fails to find its dll or dependency in VS 2013 Package Manager Console

I'm using VS Express 2013 .Net 4.5. I'm designing in MVC5 and EF6 with MS SQLServer LocalDB in an Oracle VirtualBox Windows 7 64bit client.
I am trying to apply SQL Server LocalDb migrations with the command:
PM> Enable-Migrations -ContextTypeName SGHWA_MVC.Models.Context
This always fails.
My limited web knowledge is with Web Forms so I am completely new to MVC and EF. Also I have never used PMC and Powershell. I have searched for solutions but have not found questions similar to this error that Package Manager Console produces.
First there is a warning:-
Cannot determine a valid start-up project. Using project 'SGHWA_MVC' instead. Your configuration file and working directory may not be set as expected. Use the -StartUpProjectName parameter to set one explicitly. Use the -Verbose switch for more information.
PCM drop-down box shows the Default project correctly as SGHWA_MVC. The solution property pages show this one project as the start-up project.
I went to http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference but could not see the -StartUpProjectName parameter mentioned. I'm not sure to which command this parameter applies.
Then the first error appears:-
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file://\W7O2007\Users\Admin\Documents\Visual Studio 2013\Projects\SGHWA_MVC\packages\EntityFramework.6.1.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported.
(Exception from HRESULT: 0x80131515)"At \W7O2007\Users\Admin\Documents\Visual Studio 2013\Projects\SGHWA_MVC\packages\EntityFramework.6.1.0\tools\EntityFramework.psm1:780 char:62
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $ToolsPath EntityFramework.PowerShell.Utility.dll))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
It suggests the file is not there to be loaded but it does exist on the PC at the path shown. I suspect it is the Join-Path that fails but am unsure how to test this.
The packages.config files has a line:-
(leading < removed) package id="Powershell.Deployment" version="1.1.0.0" targetFramework="net45" />
My research shows it could be permissions, remote access, that the Project Build should have Generate Serialization Assembly as 'On', 'Off' or 'Auto' or even NuGet packages that cause this but I cannot determine if it is a PMC, NuGet, Powershell or Windows problem.
Two more error messages appear relating to similar problems in EntityFramework.psm1 and seem to be related to this first problem.
Please can anyone advise the likely cause and guide me through what/how to test and solve this?
I realize this is an old thread, but I just ran into this problem using a newly-installed copy of Microsoft Visual Studio 2015 Enterprise with Update 1.
My solution was to delete this folder:
C:\Users\\(my user ID)\\.nuget\packages\EntityFramework\6.1.3
and allow it to be regenerated the next time the Entity Framework is added to a project. Originally, the PowerShell DLL's were missing from this folder. Strange.
Your question has several parts.
First, you cannot find the documentation, and you have it at your fingertips:
Update-Database -?
Then, you can read at the bottom of this help:
TO see the examples, type: "get-help Update-Database -examples".
For more information, type: "get-help Update-Database -detailed".
For technical information, type: "get-help Update-Database -full".
Second, -StartupProjectName is required to find the configuration file that has the required connection string (you also specify the connection directly using another options) NOTE: This has nothing to do with the solution's startup project
And, if having this clear doesn't solve the problem, try uninstalling and reinstalling the EntityFramework package (in case something went wrong). Take into account that, if you have several projects, it's possible that you need to do this for all the affected projects. You can do this more easily using the Manage Nuget Packages for Solution... menu option.
Edit
(Added to help choose the right Default project in Package Manager Console or specify -ProjectName).
I forgot to answer the most important part of the question: for Migrations commands to work, it's necessary to run them on a project that references the EF assemblies. This solves the missing assembly problem.
In this case it's clear that the chosen StartUpProject, which is the Web App have the connection strings, but doesn't have a reference to EF. That's why running the command fails. And most probably the command is being run with this as the default project in the console.
To solve this, you need to run Migrations within a project which has references to EF, and it will work flawlessly: choose that project in the drop down list named "Default project" on the top bar of the Package Manager Console.
This can also be done by specifying the -ProjectName option, which must point to the project containing the Migration configuration class, and thus, have also the reference to EF. NOTE: you must also sepcify the -ConfigurationTypeName param if you have several migrations for several contexts, as supported from EF 6.

Nuget Packages Installation

I have a solution which has a two projects. In the both the projects I have packages.config file which has the list of packages that the project uses. Whenever I build the solution I'm getting the below error
The command "*\Tools\nuget install \packages.config -o \Packages" exited with code 3.**
(replaced folder path with **)
I have installed all the packages manually using package manager console. The installation is successful. When I build the solution now i'm getting the below error
The command "*\Tools\nuget install \packages.config -o \Packages" exited with code 1.**
I have cleared the cache of packages. Still I get this error. Not sure why the solution build is trying to install the packages.
You can try adding -verbosity detailed to your command *\Tools\nuget install \packages.config -o \Packages to get detailed error message to help you investigate the cause.
This was happening in a new CI build I set up yesterday. The problem was that NuGet.exe wasn't at the specified path.
"exited with code 3." wasn't an error from NuGet.exe but from MSBuild.
If you were using TFS, be sure to include the location of the Nuget package in the Source Settings of build definition. This error can indicate it cannot access the files.

Categories