无法使用dotnet CLI和nuspec文件打包NuGet软件包 [英] Unable to pack a NuGet package using dotnet CLI and nuspec file

查看:120
本文介绍了无法使用dotnet CLI和nuspec文件打包NuGet软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个项目要从.NET Framework 4.7迁移到.NET Standard 2.0。结果,我尝试使用 dotnet pack 命令创建我的NuGet软件包,同时使用我的 nuspec 文件与令牌。我有几个可为我生成版本号的自定义生成脚本。我生成的文件不是版本控制的一部分,但是 nuspec 文件是为什么我想尝试找到一种使令牌工作的方法的原因,否则我会卡住

I have several projects that I'm migrating from .NET Framework 4.7 to .NET Standard 2.0. As a result, I'm trying to use the dotnet pack command to create my NuGet package while using my nuspec file with tokens. I have several custom build scripts that generate the version number for me. My generated files are not apart of version control but nuspec file is hence why I'd like to try and find a way to get the tokens to work, otherwise I'm stuck writing new scripts.

我要做的第一件事是在项目文件中将 GenerateAssemblyInfo 设置为false。在我最简单的项目中, csproj 文件如下所示:

The first thing I did was to set the GenerateAssemblyInfo to false in the project files. In my most simplest project, the csproj file looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
     <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>

然后我有一个 AssemblyInfo.cs 我将生成作为生成过程的一部分。在编译项目之前,该文件如下所示:

I then have an AssemblyInfo.cs that I generate as part of my build process. The file looks like this before I compile the project:

using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyCompany("Company Name")]
[assembly: AssemblyCopyright("Copyright © 2019")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

[assembly: AssemblyTitle("The Title")]
[assembly: AssemblyDescription("The Description")]
[assembly: AssemblyProduct("The Product")]
[assembly: ComVisible(false)]
[assembly: Guid("48d6ef54-a8fb-4876-8a9a-2fb8e8cd27e7")]
[assembly: AssemblyVersion("6.0.0.0")]
[assembly: AssemblyFileVersion("6.0.0.0")]

然后我有了一个 .nuspec 文件我用来创建如下所示的NuGet包的方法:

I then have a .nuspec file that I use to create my NuGet package which looks like this:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>My name</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes>My Release Notes</releaseNotes>
    <copyright>Copyright 2019</copyright>
    <projectUrl>http://url.local</projectUrl>
  </metadata>
</package>

经过大量阅读(不喜欢曾经为.NET Core撰写新文档的人)这是我需要运行以使用我的 nuspec 文件的命令:
dotnet pack SubFolder\MyProject.Model.csproj / p:NuspecFile = MyProject.Model.nuspec / p:NuspecBasePath = nuget

After much reading (not a fan of who ever wrote the new docs for .NET Core) I believe this is the command I need to run in order to use my nuspec file: dotnet pack SubFolder\MyProject.Model.csproj /p:NuspecFile=MyProject.Model.nuspec /p:NuspecBasePath=nuget

结果是此错误:


NuGet.Build.Tasks.Pack.targets(202,5):错误:
尝试解析属性'的值时发生错误清单
文件中的版本。 [F:\Git\MyProject\Model\MyProject.Model\MyProject.Model.csproj]

NuGet.Build.Tasks.Pack.targets(202,5): error : An error occured while trying to parse the value '' of property 'version' in the manifest file. [F:\Git\MyProject\Model\MyProject.Model\MyProject.Model.csproj]

NuGet.Build.Tasks.Pack.targets( 202,5):错误:值不能为null
或空字符串。
[F:\Git\MyProject\Model\MyProject.Model\MyProject.Model.csproj]

NuGet.Build.Tasks.Pack.targets(202,5): error : Value cannot be null or an empty string. [F:\Git\MyProject\Model\MyProject.Model\MyProject.Model.csproj]

NuGet.Build.Tasks。 Pack.targets(202,5):错误:参数名称:值
[F:\Git\MyProject\Model\MyProject.Model\MyProject.Model.csproj]

NuGet.Build.Tasks.Pack.targets(202,5): error : Parameter name: value [F:\Git\MyProject\Model\MyProject.Model\MyProject.Model.csproj]

基于输出,很明显底层目标文件没有从我的 AssemblyInfo.cs ,而是尝试直接从 csproj 文件中获取值。因此,我尝试简化过程并运行以下命令: dotnet pack MyProject.Model\MyProject.Model.csproj 创建了我的NuGet程序包,但其中没有元数据我的 nuspec 或我的 AssemblyInfo.cs 文件中。

Based on the output, it's clear that the underlying targets file isn't grabbing the values out of my AssemblyInfo.cs but rather is trying to grab the values directly out of the csproj file instead. So I tried to simplify the process and ran this command: dotnet pack MyProject.Model\MyProject.Model.csproj which created my NuGet package, but did not have the metadata in my nuspec or in my AssemblyInfo.cs file.

我在 dotnet-cli NuGet 项目中都阅读了很多GitHub上的未解决问题。与我所经历的相似,但没有一个给我有效的解决方案。有人认为这是一个错误还是我遗漏了一些东西?

I've read a lot of open issues on GitHub from both the dotnet-cli and NuGet projects that seem to be similar to what I'm experiencing, but none of them have given me a solution that works. Does anyone else think this is a bug or am I missing something?

推荐答案

我遇到了同样的问题,并通过添加<$来解决了c $ c>< NuspecProperties> 到csproj,如下所示: https ://github.com/NuGet/Home/issues/6636

I had same problem and solved it by adding <NuspecProperties>to csproj as suggested here: https://github.com/NuGet/Home/issues/6636

<NuspecFile>package.nuspec</NuspecFile>
<NuspecProperties>$(NuspecProperties);configuration=$(Configuration)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);version=$(Version)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);id=$(PackageId)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);author=$(Authors)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);PackageProjectUrl=$(PackageProjectUrl)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);Description=$(Description)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);PackageReleaseNotes=$(PackageReleaseNotes)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);Copyright=$(Copyright)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);PackageTags=$(PackageTags)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);RepositoryType=$(RepositoryType)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);RepositoryUrl=$(RepositoryUrl)</NuspecProperties>

这篇关于无法使用dotnet CLI和nuspec文件打包NuGet软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆