相关疑难解决方法(0)

如何在Visual Studio 2017中运行MSBuild包目标

我的问题是类似这个这个.

我想在Visual Studio 2017 RC中打包.Net Framework库.在带有project.json构建系统的VS 2015中,我能够通过将自定义目标文件导入.xproj文件来实现此目的.此自定义目标文件负责创建nuspec文件(如果该文件不存在),然后运行nuget pack,将生成的包复制到本地Feed位置等.

我是否需要在2017年做类似的事情(还没有认真努力)或者我能以某种方式在我的.csproj文件中启用包目标吗?

此处的文档仅显示从命令行运行pack目标.

编辑: 我正在尝试从夜间构建中引用Nuget 4.0 exe的以下自定义目标...

<Target Name="PackNugets"  AfterTargets="Build">    
  <PropertyGroup>
    <NugetV4Path>$([System.IO.Path]::GetFullPath('path to nuget.exe'))</NugetV4Path>
  </PropertyGroup>

  <Exec Command="&quot;$(NugetV4Path)\nuget.exe&quot; pack &quot;$(MSBuildProjectDirectory)\$(PackageId).csproj&quot; -Symbols -OutputDirectory bin -Properties Configuration=Release"/>
</Target>
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误

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) …
Run Code Online (Sandbox Code Playgroud)

c# msbuild nuget visual-studio-2017

8
推荐指数
2
解决办法
1万
查看次数

从 NuGet 包中排除目标框架

如何从 nuspec(NuGet 包)生成中排除特定目标框架?

这是我的 csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFrameworks>netstandard2.0;net5.0;net5.0-windows</TargetFrameworks>
        <IsPackable>true</IsPackable>
    </PropertyGroup>

    <PropertyGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
        <IsPackable>false</IsPackable>
    </PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

dotnet pack命令生成 NuGet 包,其中不仅包含所有目标框架netstandard2.0,而且net5.0

生成的 nuspec:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>ExampleLibrary</id>
    <version>1.0.0</version>
    <authors>ExampleLibrary</authors>
    <description>Package Description</description>
    <dependencies>
      <group targetFramework="net5.0" />
      <group targetFramework="net5.0-windows7.0" />
      <group targetFramework=".NETStandard2.0" />
    </dependencies>
  </metadata>
</package>
Run Code Online (Sandbox Code Playgroud)

csproj nuget .net-core

5
推荐指数
1
解决办法
1433
查看次数

标签 统计

nuget ×2

.net-core ×1

c# ×1

csproj ×1

msbuild ×1

visual-studio-2017 ×1