Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
Labels
Resolution:Duplicate This issue appears to be a Duplicate of another issue

Comments

@maartenba
Copy link
Contributor

maartenba commented Mar 15, 2017

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.

@emgarten emgarten added the Resolution:Duplicate This issue appears to be a Duplicate of another issue label Mar 15, 2017
@emgarten
Copy link
Member

There is an issue tracking this here: #4491

nuget.exe doesn't support NETCore SDK projects currently, and the error message you get is confusing as you can see.

@emgarten
Copy link
Member

The workaround is to use msbuild /t:pack

@maartenba
Copy link
Contributor Author

Got it, thanks Justin!

@v1ct0rv
Copy link

v1ct0rv commented Mar 30, 2017

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?

@emgarten
Copy link
Member

@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.

@v1ct0rv
Copy link

v1ct0rv commented Mar 30, 2017

@emgarten I ran dotnet pack and works, the package is generated, this another workaround until nuget 4.0 guy's fix the issue.

@tofutim
Copy link

tofutim commented Apr 22, 2017

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\work\1b384cbcb583432\src\Loqu8.Azure.Mobile.Client.SQLiteStore\Loqu8.Azure.Mobile.Client.SQLiteStore.csproj -OutputDirectory C:\TeamCity\buildAgent\work\1b384cbcb583432\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\work\1b384cbcb583432\src\Loqu8.Azure.Mobile.Client.SQLiteStore\Loqu8.Azure.Mobile.Client.SQLiteStore.csproj -OutputDirectory C:\TeamCity\buildAgent\work\1b384cbcb583432\output -Properties Configuration=Loqu8
[16:42:59][pack] in directory: C:\TeamCity\buildAgent\work\1b384cbcb583432\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\MSBuild\15.0\bin'.
[16:43:01][pack] Packing files from 'C:\TeamCity\buildAgent\work\1b384cbcb583432\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

@edemesa
Copy link

edemesa commented May 26, 2017

@v1ct0rv I think your issue is related to a spelling error in: /t:pack MyProyect.csproj

@vdrasutis
Copy link

vdrasutis commented May 11, 2018

Same issue using 4.6.2 NuGet.exe ...

It it caused big pain.

  • As nuspec can`t be used, because properties like "$id$", "$version$" and so on which is mapped to AssemblyInfo.cs properties (https://docs.microsoft.com/en-us/nuget/reference/nuspec).
  • I try to use nuspec with "dotnet pack" then I get errors like null value and so on, as I am not able to map properties from AssemblyInfo.cs to nuspec.
  • Or get errors like this when trying to pack project:
    Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGet.Frameworks1093899.NuGetFramework'.

@Salgat
Copy link

Salgat commented May 18, 2018

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'.

@outadoc
Copy link

outadoc commented Oct 17, 2018

In our case, the issue was solved by updating NuGet: nuget.exe update -self.

@praveena-m
Copy link

Using Nuget 4.9.1 version resolved my issue.
capture

@maryammadzadeh
Copy link

@praveena-m your solution worked for me too!

@brienRosenquist
Copy link

@praveena-m's solution worked for me also. Time to update the NuGet task to allow for choosing version 4.

Kaneraz added a commit to factset/AgDatabaseMove that referenced this issue Mar 6, 2019
Kaneraz added a commit to factset/AgDatabaseMove that referenced this issue Mar 6, 2019
* chore(ci): create multiple jobs

* chore(ci): further split the jobs

* chore(ci): correct invalid job name

* chore(ci): default to windows host

* chore(ci): use matrix strategy

* chore(ci): restore before building for cleanup code

A reference was not found during build for cleanup code. Perhaps a restore first will solve the problem.

* chore(ci): create build directory

* chore(ci): add the pipeline under build

* chore(ci): set up a nuget package

* chore(ci): add metadata for nuget

And remove the JetBrains reference which isn't needed.

* chore(ci): don't specify an output directory

* chore(ci): don't try to publish everything

* chore(ci): nuget doesn't support NETCore SDK projects

NuGet/Home#4808

* chore(ci): pack each build configuration

* chore(ci): only pack for release

* use variables collection instead of $ reference

* chore(ci): push to nuget
@JeffreyCA
Copy link

If using Azure Pipelines with YAML, add this task in the beginning:

steps:
  - task: NuGetToolInstaller@0
    inputs:
      versionSpec: '4.9.1'

@marc-wilson
Copy link

marc-wilson commented Apr 24, 2019

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).

@replicaJunction
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution:Duplicate This issue appears to be a Duplicate of another issue
Projects
None yet
Development

No branches or pull requests