vsts 将 .net 标准 2 打包成 nuget
vsts pack .net standard 2 into nuget
在 VSTS 构建过程中,我一整天都在尝试打包这个 nuget 包。它是 .net 标准 2.0 项目
这是我不断遇到的错误之一
Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'.
这是控制台在尝试打包时打印出来的。
******************************************************************************
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\s\MyProject.Core.Framework.Logging\MyProject.Core.Framework.Logging.csproj
d:\a\_tool\NuGet.1.0\x64\nuget.exe pack d:\a\s\MyProject.Core.Framework.Logging\MyProject.Core.Framework.Logging.csproj -NonInteractive -OutputDirectory d:\a\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 Studio17\Enterprise\MSBuild.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Packing files from 'd:\a\s\MyProject.Core.Framework.Logging\bin\release\netstandard2.0'.
Using 'MyProject.Core.Framework.Logging.1.0.0.nuspec' for metadata.
Add file 'd:\a\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.1.0\x64\nuget.exe failed with return code: 1
An error ocurred while trying to pack the files.
这里是 nuspec 文件
<?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>
我也在 nuspec 文件中尝试了 $version$。
我已经选择了所有自动包版本控制选项,但我总是会遇到一些错误。
如果需要,我可以提供更多详细信息。
需要使用dotnet pack命令。
您不需要"dotnet pack",您仍然可以使用"msbuild pack"。
但是您需要使用 "Nuget-Toolinstaller" 插入一个额外的步骤,以指定 Nuget-Version >= 4.3。请参阅 了解如何执行此操作。
此外,您可能希望坚持使用 <5.0.0 的版本。
为此,您可以指定 4.x >=4.3
。 4.3.0好像解决了这个问题
在 VSTS 构建过程中,我一整天都在尝试打包这个 nuget 包。它是 .net 标准 2.0 项目
这是我不断遇到的错误之一
Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'.
这是控制台在尝试打包时打印出来的。
******************************************************************************
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\s\MyProject.Core.Framework.Logging\MyProject.Core.Framework.Logging.csproj
d:\a\_tool\NuGet.1.0\x64\nuget.exe pack d:\a\s\MyProject.Core.Framework.Logging\MyProject.Core.Framework.Logging.csproj -NonInteractive -OutputDirectory d:\a\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 Studio17\Enterprise\MSBuild.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Packing files from 'd:\a\s\MyProject.Core.Framework.Logging\bin\release\netstandard2.0'.
Using 'MyProject.Core.Framework.Logging.1.0.0.nuspec' for metadata.
Add file 'd:\a\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.1.0\x64\nuget.exe failed with return code: 1
An error ocurred while trying to pack the files.
这里是 nuspec 文件
<?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>
我也在 nuspec 文件中尝试了 $version$。
我已经选择了所有自动包版本控制选项,但我总是会遇到一些错误。
如果需要,我可以提供更多详细信息。
需要使用dotnet pack命令。
您不需要"dotnet pack",您仍然可以使用"msbuild pack"。
但是您需要使用 "Nuget-Toolinstaller" 插入一个额外的步骤,以指定 Nuget-Version >= 4.3。请参阅
此外,您可能希望坚持使用 <5.0.0 的版本。
为此,您可以指定 4.x >=4.3
。 4.3.0好像解决了这个问题