Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When running the NuGet pack command I get the error: 'AutoMapper' already has a dependency defined for 'NETStandard.Library'

I'm having an issue packaging my own nuget package, which includes AutoMapper 5.0.2. This is only producing an error within the Visual Studio Team Services (VSTeam) Build servers.

My project is using .NET 4.6.1

Any ideas on how to fix?

Here is the error:

2016-07-08T23:46:44.5801667Z C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.102.0\agent\worker\tools\NuGet.exe pack "C:\a\1\s\Project.csproj" -OutputDirectory "C:\a\1\s\Project\bin\release" -Properties Configuration=release -IncludeReferencedProjects 
2016-07-08T23:46:45.0458195Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2016-07-08T23:46:45.0468395Z Attempting to build package from 'Project.csproj'.
2016-07-08T23:46:45.1942694Z Packing files from 'C:\a\1\s\Project\bin\Release'.
2016-07-08T23:46:45.3942642Z ##[error]**'AutoMapper' already has a dependency defined for 'NETStandard.Library'.**
2016-07-08T23:46:45.4142626Z ##[error]System.Exception: Unexpected exit code 1 returned from tool NuGet.exe
2016-07-08T23:46:45.4152639Z ##[error] at Microsoft.TeamFoundation.DistributedTask.Task.Internal.PowerShell.InvokeToolCmdlet.ProcessRecord()
2016-07-08T23:46:45.4152639Z ##[error] at System.Management.Automation.CommandProcessor.ProcessRecord()

I also opened an issue on GitHub: https://github.com/AutoMapper/AutoMapper/issues/1499

like image 262
Phobis Avatar asked Jul 09 '16 02:07

Phobis


People also ask

Why does automapper not work with my NuGet package?

The problem is that your NuGet Package Manager is too old. You need NuGet 2.12since this supports the newer .NETStandard frameworks that the AutoMapper 5.0.1 NuGet package is using. The AutoMapper has a group dependency which specifies a target framework of .NETStandard.

Why is my NuGet package missing from my project?

This project references NuGet package (s) that are missing on this computer. Use NuGet Package Restore to download them. The missing file is {name}. This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are not presently installed on the computer or in the project.

Is it possible to use automapper with Visual Studio 2012?

'AutoMapper' already has a dependency defined for 'Microsoft.CSharp' Unfortunately NuGet 2.12 is not available for Visual Studio 2012 but is available for Visual Studio 2013. So either you need to update to Visual Studio 2013 or above, or you will have to use the older AutoMapper NuGet package which does not support .NETStandard.

What are the dependencies of automapper and htmlagilitypack?

'AutoMapper' already has a dependency defined for 'Microsoft.CSharp' 2 'HtmlAgilityPack' already has a dependency defined for 'System.Net.Http' Hot Network Questions


2 Answers

You need to install new Nuget version for your visual studio version.

Get it from here Nuget gallery

like image 189
Alienalone Avatar answered Nov 15 '22 11:11

Alienalone


I was able to fix/workaround the issue by putting a PowerShell script in to download the latest NuGet. Then I pointed all of the NuGet tasks to this new nuget.exe. Pros: builds are working again, Cons: each build downloads NuGet again, causing unnecessary load on NuGet.org.

Here is my PowerShell:

$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = "$(build.sourcesdirectory)/nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose
nuget
like image 26
Phobis Avatar answered Nov 15 '22 10:11

Phobis