我的问题类似于 this 和 this。
我想在 Visual Studio 2017 RC 中打包一个 .Net Framework 库。在使用 project.json 构建系统的 VS 2015 中,我能够通过将自定义 targets 文件导入到 .xproj 文件中来完成此操作。这个自定义 targets 文件负责创建 nuspec 文件(如果不存在),然后运行 nuget pack,将生成的 packages 复制到本地 feed 位置等。
在 2017 中,我需要做类似的事情吗(还没有认真尝试过),或者我可以在我的 .csproj 文件中启用 pack target?
文档 here 只显示从命令行运行 pack target 的方法。
编辑: 我正在尝试下面的自定义 target,引用来自 nightly builds 的 Nuget 4.0 exe...
但是我收到了以下错误。
我想在 Visual Studio 2017 RC 中打包一个 .Net Framework 库。在使用 project.json 构建系统的 VS 2015 中,我能够通过将自定义 targets 文件导入到 .xproj 文件中来完成此操作。这个自定义 targets 文件负责创建 nuspec 文件(如果不存在),然后运行 nuget pack,将生成的 packages 复制到本地 feed 位置等。
在 2017 中,我需要做类似的事情吗(还没有认真尝试过),或者我可以在我的 .csproj 文件中启用 pack target?
文档 here 只显示从命令行运行 pack target 的方法。
编辑: 我正在尝试下面的自定义 target,引用来自 nightly builds 的 Nuget 4.0 exe...
<Target Name="PackNugets" AfterTargets="Build">
<PropertyGroup>
<NugetV4Path>$([System.IO.Path]::GetFullPath('path to nuget.exe'))</NugetV4Path>
</PropertyGroup>
<Exec Command=""$(NugetV4Path)\nuget.exe" pack "$(MSBuildProjectDirectory)\$(PackageId).csproj" -Symbols -OutputDirectory bin -Properties Configuration=Release"/>
</Target>
但是我收到了以下错误。
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)
这与csproj中的某个属性有关吗?NugetFramework是否指TargetFramework
?
我正在我的csproj中针对net452
进行目标设置,如果有帮助的话。
编辑:该异常确实与nuget尝试解析TargetFramework
有关,但不清楚它是在我的csproj还是依赖项上失败了...
dotnet pack -c Release
或者将 RELEASE 替换为你的环境。对我来说有效。 - VictorV