无法在VST上打包Nuget包无法强制转换类型为';System.String';输入';NuGet.Frameworks.NuGetFramework';

无法在VST上打包Nuget包无法强制转换类型为';System.String';输入';NuGet.Frameworks.NuGetFramework';,nuget,azure-devops,Nuget,Azure Devops,在运行“pack”时,我遇到以下错误 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-05T1

在运行“pack”时,我遇到以下错误

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: 4.0.0.2283
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

到目前为止,似乎一切都很顺利,所以我有点卡住了。欢迎任何想法。

这似乎是使用VSTS内置的Nuget pack项的问题。我把它换成了一个命令行元素来调用dotnetpack,现在它可以工作了。

在VSTS中,我使用了“dotnetpack”而不是“nuget pack”。所以这个问题就解决了

为了在VST上发布nuget lib,我选择了以下插件序列:

  • 获取来源
  • nuget恢复
  • 网络构建
  • 网络包
  • 努吉推

我的.net标准2.0类库也有同样的问题,我被打包到一个nuget包中。下面是您需要添加以替换nuget pack步骤的步骤的屏幕截图

要添加的步骤类型

下面是我如何配置步骤的

要使pack命令起作用,您需要确保csproj具有以下标签:

<PackageId>*qualified_package_name*</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
*限定的\u包\u名称*
真的
如果您是从旧式CSPROJ文件迁移而来,这一点尤其重要


使用Nuget 4.9.1版本解决了我的问题。

您使用的代理是什么?项目是否从VS2015迁移到VS2017,您能否将项目上载到一个驱动器?正确答案属于@praveena-m->。对不起,我不允许对你的帖子发表评论。此外,您可能希望坚持使用版本=4.3。这个问题似乎在4.3.0中得到了解决。我认为您还需要使用“dotnet推送”而不是“nuget推送”。这个问题已经在更新版本的nuget中得到了解决。我通过将nuget版本设置为4.9.1使其正常工作。这是正确的答案,因此您可以坚持执行nuget命令,而不是求助于dotnet.exe命令集。