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 · 11 comments

Comments

Projects
None yet
8 participants
@maartenba
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

This comment has been minimized.

Show comment
Hide comment
@emgarten

emgarten Mar 15, 2017

Collaborator

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.

Collaborator

emgarten commented Mar 15, 2017

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 emgarten closed this Mar 15, 2017

@emgarten

This comment has been minimized.

Show comment
Hide comment
@emgarten

emgarten Mar 15, 2017

Collaborator

The workaround is to use msbuild /t:pack

Collaborator

emgarten commented Mar 15, 2017

The workaround is to use msbuild /t:pack

@maartenba

This comment has been minimized.

Show comment
Hide comment
@maartenba

maartenba Mar 15, 2017

Contributor

Got it, thanks Justin!

Contributor

maartenba commented Mar 15, 2017

Got it, thanks Justin!

@V1ct0rV

This comment has been minimized.

Show comment
Hide comment
@V1ct0rV

V1ct0rV 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?

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

This comment has been minimized.

Show comment
Hide comment
@emgarten

emgarten Mar 30, 2017

Collaborator

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

Collaborator

emgarten commented Mar 30, 2017

@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

This comment has been minimized.

Show comment
Hide comment
@V1ct0rV

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

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

This comment has been minimized.

Show comment
Hide comment
@tofutim

tofutim 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

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

This comment has been minimized.

Show comment
Hide comment
@edemesa

edemesa May 26, 2017

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

edemesa commented May 26, 2017

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

@Drasius2

This comment has been minimized.

Show comment
Hide comment
@Drasius2

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

Drasius2 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

This comment has been minimized.

Show comment
Hide comment
@Salgat

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

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

This comment has been minimized.

Show comment
Hide comment
@outadoc

outadoc Oct 17, 2018

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

outadoc commented Oct 17, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment