Getting an error with NuGet 4.0 pack command (nuget.exe):
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'.
at NuGet.ProjectManagement.NuGetProject.GetMetadata[T](String key)
at NuGet.ProjectManagement.PackagesConfigNuGetProject..ctor(String folderPath, Dictionary`2 metadata)
at CallSite.Target(Closure , CallSite , Type , Object , Dictionary`2 )
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at NuGet.CommandLine.ProjectFactory.AddDependencies(Dictionary`2 packagesAndDependencies)
at NuGet.CommandLine.ProjectFactory.ProcessDependencies(PackageBuilder builder)
at NuGet.CommandLine.ProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder)
at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
at NuGet.CommandLine.PackCommand.ExecuteCommand()
at NuGet.CommandLine.Command.ExecuteCommandAsync()
at NuGet.CommandLine.Command.Execute()
at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
Unfortunately can not provide a repro project. The project is a netstandard1.0 one.
There is an issue tracking this here: https://github.com/NuGet/Home/issues/4491
nuget.exe doesn't support NETCore SDK projects currently, and the error message you get is confusing as you can see.
The workaround is to use msbuild /t:pack
Got it, thanks Justin!
Hi,
I'm creating a .net standard library.
I'm running $ /c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe /t:pack MyProyect.csproj
I'm getting the error:
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1008: Only one project can be specified.
Switch: MyProyect.csproj
For switch syntax, type "MSBuild /help"
This is the content of MyProject.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
</Project>
What I'm doing wrong?
@victorv977 that is an msbuild error and not related to Pack. You should see the same result with /t:clean
. Typically this error happens when msbuild is unable to determine which project to operate on, but in your example you specified the project directly, so it's not clear why this would happen.
@emgarten I ran dotnet pack
and works, the package is generated, this another workaround until nuget 4.0 guy's fix the issue.
I also had the same problem using nuget pack from TeamCity (nuget 4.1).
[Step 5/5] pack: Create NuGet package from src\Loqu8.Azure.Mobile.Client.SQLiteStore\Loqu8.Azure.Mobile.Client.SQLiteStore.csproj (2s)
[16:42:59][pack] NuGet command: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe pack C:\TeamCity\buildAgent\work1b384cbcb583432\src\Loqu8.Azure.Mobile.Client.SQLiteStore\Loqu8.Azure.Mobile.Client.SQLiteStore.csproj -OutputDirectory C:\TeamCity\buildAgent\work1b384cbcb583432\output -Properties Configuration=Loqu8
[16:42:59][pack] Starting: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe pack C:\TeamCity\buildAgent\work1b384cbcb583432\src\Loqu8.Azure.Mobile.Client.SQLiteStore\Loqu8.Azure.Mobile.Client.SQLiteStore.csproj -OutputDirectory C:\TeamCity\buildAgent\work1b384cbcb583432\output -Properties Configuration=Loqu8
[16:42:59][pack] in directory: C:\TeamCity\buildAgent\work1b384cbcb583432\src\Loqu8.Azure.Mobile.Client.SQLiteStore
[16:42:59][pack] JetBrains TeamCity NuGet Runner 8.0.46533.9
[16:42:59][pack] Registered additional extensions from paths: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\plugins-4.0
[16:42:59][pack] Starting NuGet.exe 4.1.0.2450 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe
[16:43:00][pack] Attempting to build package from 'Loqu8.Azure.Mobile.Client.SQLiteStore.csproj'.
[16:43:00][pack] MSBuild auto-detection: using msbuild version '15.1.1012.6693' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild15.0\bin'.
[16:43:01][pack] Packing files from 'C:\TeamCity\buildAgent\work1b384cbcb583432\src\Loqu8.Azure.Mobile.Client.SQLiteStore\bin\Loqu8\netstandard1.4'.
[16:43:02][pack] Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'.
[16:43:02][pack] Process exited with code 1
[16:43:02][pack] Process exited with code 1
[16:43:02][Step 5/5] Step NuGet Pack failed
@V1ct0rV I think your issue is related to a spelling error in: /t:pack MyProyect.csproj
Same issue using 4.6.2 NuGet.exe ...
It it caused big pain.
Same issue as @Drasius2, which makes this a pain as we're migrating part of our projects over.
Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGet.Frameworks1093899.NuGetFramework'.
In our case, the issue was solved by updating NuGet: nuget.exe update -self
.
Using Nuget 4.9.1 version resolved my issue.
@praveena-m your solution worked for me too!
@praveena-m's solution worked for me also. Time to update the NuGet task to allow for choosing version 4.
If using Azure Pipelines with YAML, add this task in the beginning:
steps:
- task: NuGetToolInstaller@0
inputs:
versionSpec: '4.9.1'
dotnet pack
did it for me. My problem was the AzureDevOps Task that I was using was the Nuget step. Once I switched to use the dotnet core step instead, pack worked fine.
I'm on a mac if that matters (it's a local build agent).
Adding on a bit of info just because Google brought me here.
Azure DevOps encounters this error because by default, it uses the cached version of NuGet.exe that's available on its build agent. At the time of this writing, that was 4.3.0 for me.
@JeffreyCA 's solution works, but that line will force your build to always use version 4.9.1 of NuGet. I prefer to use the latest version available in case there are other bug fixes I want, so I modified the YAML slightly to always check for the latest version.
My step looks like this:
- task: NuGetToolInstaller@1
inputs:
checkLatest: true
Most helpful comment
Using Nuget 4.9.1 version resolved my issue.
