【发布时间】:2017-01-31 19:18:50
【问题描述】:
我想在 Visual Studio 2017 RC 中打包一个 .Net Framework 库。在带有 project.json 构建系统的 VS 2015 中,我能够通过将自定义目标文件导入 .xproj 文件来完成此操作。此自定义目标文件负责创建 nuspec 文件(如果不存在),然后运行 nuget pack,将生成的包复制到本地提要位置等。
我是否需要在 2017 年做类似的事情(还没有认真努力),还是我可以在我的 .csproj 文件中启用 pack 目标?
文档here 仅显示从命令行运行打包目标。
编辑: 我正在尝试以下自定义目标,该目标引用来自每晚构建的 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 还是在依赖项中失败...
【问题讨论】:
标签: c# msbuild nuget visual-studio-2017