3

I have been trying to pack this nuget package for an entire day in the VSTS build process. it is .net standard 2.0 project

This is one of the errors i keep getting

Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'.

This the print out from the console when it attempts to pack.

******************************************************************************
Starting: NuGet pack
******************************************************************************
==============================================================================
Task         : NuGet
Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Package Management and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
Version      : 2.0.15
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613747)
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Attempting to pack file: d:\a\1\s\MyProject.Core.Framework.Logging\MyProject.Core.Framework.Logging.csproj
d:\a\_tool\NuGet\4.1.0\x64\nuget.exe pack d:\a\1\s\MyProject.Core.Framework.Logging\MyProject.Core.Framework.Logging.csproj -NonInteractive -OutputDirectory d:\a\1\a -Properties Configuration=release -Verbosity Detailed
NuGet Version: 4.1.0.2450
Attempting to build package from 'MyProject.Core.Framework.Logging.csproj'.
MSBuild auto-detection: using msbuild version '15.4.8.50001' 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.
Packing files from 'd:\a\1\s\MyProject.Core.Framework.Logging\bin\release\netstandard2.0'.
Using 'MyProject.Core.Framework.Logging.1.0.0.nuspec' for metadata.
Add file 'd:\a\1\s\MyProject.Core.Framework.Logging\bin\release\netstandard2.0\MyProject.Core.Framework.Logging.dll' to package as 'lib\netstandard2.0\MyProject.Core.Framework.Logging.dll'
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)
Error: d:\a\_tool\NuGet\4.1.0\x64\nuget.exe failed with return code: 1
An error ocurred while trying to pack the files.

here is nuspec file

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>MyrProject.Core.Framework.Logging</id>
    <version>1.0.0</version>
    <authors>Christian Green</authors>
    <owners>Christian Green</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <projectUrl>https://MyrProject.visualstudio.com/MyrProject Core Frameworks/_wiki?pagePath=/MyrProject-Core-Frameworks</projectUrl>
    <iconUrl>http://MyrProject.com/application/files/cache/c169905894409716427e11acc3bdc2df.png</iconUrl>
    <description>Package Description</description>
    <dependencies>
      <group targetFramework=".NETStandard2.0">
        <dependency id="log4net" version="2.0.8" exclude="Build,Analyzers" />
        <dependency id="Microsoft.EntityFrameworkCore.SqlServer" version="2.0.0" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
</package>

I have tried $version$ in the nuspec file also.

I have selected all the Automatic package versioning options and I always get the some error.

enter image description here

I can provide more details if needed.

ChampChris
  • 1,565
  • 5
  • 26
  • 44
  • 2
    Possible duplicate of [Unable to pack a Nuget Package on VSTS Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'](https://stackoverflow.com/questions/44924019/unable-to-pack-a-nuget-package-on-vsts-unable-to-cast-object-of-type-system-str) – Daniel Mann Nov 12 '17 at 00:15
  • That question solved my issue also – ChampChris Nov 12 '17 at 19:10

2 Answers2

6

Need to use dotnet pack command.

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
0

You don't need "dotnet pack", you can still do it with "msbuild pack". But you need to insert an extra step using "Nuget-Toolinstaller", in order to specify a Nuget-Version >= 4.3. See https://stackoverflow.com/a/53614798/2412853 about how to do that.

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.

Stefan
  • 35
  • 5