Unable to pack a Nuget Package on VSTS Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'

dotnet pack
the nuget command failed with exit code 1 and error unable to cast object of type system string
msbuild /t:pack
dotnet pack include referenced projects
nuget version
nuget pack command
dotnet pack solution
visual studio pack

On running 'pack' I am getting the following error...

2017-07-05T10:37:09.7762333Z ##[section]Starting: NuGet pack
2017-07-05T10:37:09.7762333Z ==============================================================================
2017-07-05T10:37:09.7762333Z Task         : NuGet
2017-07-05T10:37:09.7762333Z Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Package Management and MyGet.
2017-07-05T10:37:09.7762333Z Version      : 2.0.3
2017-07-05T10:37:09.7762333Z Author       : Microsoft Corporation
2017-07-05T10:37:09.7762333Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613747)
2017-07-05T10:37:09.7762333Z ==============================================================================
2017-07-05T10:37:10.9664575Z Downloading: https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe
2017-07-05T10:37:11.0954621Z Caching tool: NuGet 4.0.0 x64
2017-07-05T10:37:11.1084622Z Using version: 4.0.0
2017-07-05T10:37:11.1094622Z Found tool in cache: NuGet 4.0.0 x64
2017-07-05T10:37:11.1214629Z [command]C:\Windows\system32\chcp.com 65001
2017-07-05T10:37:11.1634626Z Active code page: 65001
2017-07-05T10:37:11.2234637Z Attempting to pack file: d:\a\1\s\src\Esoterix\Esoterix.csproj
2017-07-05T10:37:11.2294640Z [command]d:\a\_tool\NuGet\4.0.0\x64\nuget.exe pack d:\a\1\s\src\Esoterix\Esoterix.csproj -NonInteractive -OutputDirectory d:\a\1\a -Properties Configuration=release -version 1.0.0-CI-201765-103711 -Verbosity Detailed
2017-07-05T10:37:12.3087180Z NuGet Version:
2017-07-05T10:37:12.3187144Z Attempting to build package from 'Esoterix.csproj'.
2017-07-05T10:37:12.7569409Z MSBuild auto-detection: using msbuild version '15.1.1012.6693' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
2017-07-05T10:37:15.3118046Z Packing files from 'd:\a\1\s\src\Esoterix\bin\release\netcoreapp1.1'.
2017-07-05T10:37:15.7119285Z Add file 'd:\a\1\s\src\Esoterix\bin\release\netcoreapp1.1\Esoterix.dll' to package as 'lib\netcoreapp1.1\Esoterix.dll'
2017-07-05T10:37:15.7959331Z System.InvalidCastException: Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'.
2017-07-05T10:37:15.7969309Z    at NuGet.ProjectManagement.NuGetProject.GetMetadata[T](String key)
2017-07-05T10:37:15.7969309Z    at NuGet.ProjectManagement.PackagesConfigNuGetProject..ctor(String folderPath, Dictionary`2 metadata)
2017-07-05T10:37:15.7969309Z    at CallSite.Target(Closure , CallSite , Type , Object , Dictionary`2 )
2017-07-05T10:37:15.7969309Z    at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
2017-07-05T10:37:15.7969309Z    at NuGet.CommandLine.ProjectFactory.AddDependencies(Dictionary`2 packagesAndDependencies)
2017-07-05T10:37:15.7969309Z    at NuGet.CommandLine.ProjectFactory.ProcessDependencies(PackageBuilder builder)
2017-07-05T10:37:15.7969309Z    at NuGet.CommandLine.ProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder)
2017-07-05T10:37:15.7969309Z    at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
2017-07-05T10:37:15.7969309Z    at NuGet.CommandLine.PackCommand.ExecuteCommand()
2017-07-05T10:37:15.7969309Z    at NuGet.CommandLine.Command.ExecuteCommandAsync()
2017-07-05T10:37:15.7969309Z    at NuGet.CommandLine.Command.Execute()
2017-07-05T10:37:15.7969309Z    at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
2017-07-05T10:37:15.8259323Z ##[error]Error: d:\a\_tool\NuGet\4.0.0\x64\nuget.exe failed with return code: 1
2017-07-05T10:37:15.8259323Z ##[error]An error ocurred while trying to pack the files.
2017-07-05T10:37:15.8289336Z ##[section]Finishing: NuGet pack

It seems that everything is picked up fine up to this point so I'm a bit stuck . Any ideas welcome.

NuGet pack Unable to cast object of type 'System.String' to , NuGet pack Unable to cast object of type 'System. @emgarten I ran dotnet pack and works, the package is generated, this another from 'C:\Program Files (x86)\​Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin'. Try to use "dotnet pack" instead of "nuget pack" in your VSTS, it will be resolved. To publish nuget lib on VSTS, choose the following plugins sequence: Get sources; nuget restore; dotnet build; dotnet pack; nuget push

Using Nuget 4.9.1 version resolved my issue.

The art of simplicity: .NET Core, InvalidCastException: Unable to cast object of type 'System. I configured our build pipeline to Restore the NuGet packages, Build the application and publish it​. [command]D:\b\4\agent\_work\_tool\NuGet\4.1.0\x64\nuget.exe pack Files (​x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. NuGet pack Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework' #4808 Closed maartenba opened this issue Mar 15, 2017 · 17 comments

I had this same issue with my .net standard 2.0 class library I was pack into a nuget package. Here is a screenshot of the step you need to add to replace nuget pack step.

Step Type To Add

Here is how I configured the step

NuGet push for .NET Standard 2.0 Class Library, The NuGet Pack is working for my other two 32-bit and PCL class libraries. Attempting to InvalidCastException: Unable to cast object of type 'System.String​' to  Version Used: 2.6.1 Steps to Reproduce: Create console app using VS 2015 and add nuget reference to Microsoft.CodeAnalysis (.NET framework 4.6.1) On the same machine, VS 2017 comunity version is also installed.

This seems to be an issue using the Nuget pack item built in to VSTS. I swapped it out for a Command Line element to call dotnet pack instead and it now works.

NuGet pack Unable to cast object of type 'System.String , Ask questionsNuGet pack Unable to cast object of type 'System.String' to type '​NuGet. Visual Studio 2015 with NuGet 3.6.0 fails to install packages with  Nuget command and manually pass -Version in the Nuget arguments I get Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'. chrispat added the Area: Packaging label Jun 7, 2017

For pack command to work, you need to ensure that the csproj has the following tags:


This is particularly relevant if you've migrated from an old-style CSPROJ file

nuget.exe fails to pack NETCore project, InvalidCastException: Unable to cast object of type 'System.String' to type 'NuGet.​Frameworks.NuGetFramework'. at NuGet.ProjectManagement.NuGetProject. Using nuget.exe 4.0.0 build 2266 Steps Create a NETstandard class library nuget.exe pack <path to csproj> Expected Package will be created Actual Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'.

The perils of publishing a .NET Standard library to NuGet, For many developers, adding NuGet packages will be the first thing they do to a new project. NuGet Unable to cast object of type 'System. Unable to find NuGet package tfs TFS 2017 artifacts Perreault Dominic reported Sep 08, 2017 at 03:05 PM

Article: Unable to cast object of type 'System.String' to type 'System , Make sure to reference the assemblies from the project's bin folder. If using NuGet packages, ensure the project is upgraded following the steps  After creating a .NET Core application, I configured our build pipeline to Restore the NuGet packages, Build the application and publish it. Unfortunately the build failed almost immediately.

EF 6 invalid SQL - Forums, I'm using the release DB2 EF 6.0.0 nuget package, Visual Studio 2012 update 4, DB2 Windows x6410.5.1, DB2 Data Server Client 10.5 fix pack 5. I'm getting the following with data type "SYSIBM.VARCHAR" cannot be CAST to type "​SYSIBM. InvalidCastException: Unable to cast object of type 'System.Data.​Entity.Core. NuGet push for .NET Standard 2.0 Class Library Azure DevOps pipelines Dawson reported Aug 21, 2017 at 11:39 AM

  • What's the agent are you use? Did the project migrate from VS2015 to VS2017 and can you upload your project to one drive?
  • The correct answer belongs to @praveena-m -> stackoverflow.com/a/53614798/2412853. Sorry, I am not allowed to comment to your post. Additionally, you may want to stick with a Version <5.0.0. In order to do that, you can specify 4.x >=4.3. The problem seems to be resolved in 4.3.0.
  • I think you need also to use "dotnet push" instead of "nuget push"
  • This issue has been resolved in the newer version of the nuget. I got it working by setting the nuget version to 4.9.1
  • This is the correct answer so that you can stick with executing Nuget commands rather than resorting to the dotnet.exe command set.