nuget pack 不从 Visual Studio 项目读取程序集版本
我正在关注 这个关于使用 nuget.exe
创建 nuget 包的官方文档。我正在尝试从 Visual Studio 项目创建 nuspec 文件。
根据文档,当您
> nuget spec
从 .csproj
文件所在的目录运行时,它会创建一个标记化的 .nuspec
文件。然后,当您运行 nuget pack
因此,在我的示例中,我有一个名为 Logger1 的项目。运行 nuget spec
后,我有以下 .nuspec
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Yoav Klein</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
...
现在,此文档 说:
要使用这些令牌,请使用项目文件(而不仅仅是 .nuspec)运行 nuget pack。例如,使用以下命令时,.nuspec 文件中的 $id$ 和 $version$ 标记将替换为项目的 AssemblyName 和 AssemblyVersion 值:
nuget pack MyProject.csproj
我的程序集版本是:
# AssemblyInfo.cs
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
现在我运行 nuget pack Logger1.csproj< /code> ,我希望按照文档的承诺,从项目的 AssemblyVersion
中提取包的版本。
创建包后,我检查了创建的包中的 .nuspec 文件:
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Logger1</id>
<version>1.0.0</version>
如您所见,由于某种原因,它没有采用正确的 AssemblyVersion
值,即 1.6。 0
,但始终使用值 1.0.0
。
有人可以告诉我我做错了什么吗?
NuGet版本:5.8.1.7021
只是为了确认,构建dll后,我可以看到程序集版本是1.6.0:
PS> [Reflection.AssemblyName]::GetAssemblyName("$(pwd)\bin\Debug\Logger1.dll")
Version Name
------- ----
1.6.0.0 Logger1
I'm following along this official doc about creating a nuget package with nuget.exe
. I'm trying to create a nuspec file out of a Visual Studio project.
According to the docs, when you run
> nuget spec
From the directory where your .csproj
file resides, it creates a tokenized .nuspec
file. Then, when you run nuget pack <project-name>.csproj
the values from the project file are used to replace the tokens in the nuspec file.
So in my example, I have a project called Logger1
. After running nuget spec
, I have the following .nuspec
<package >
<metadata>
<id>$idlt;/id>
<version>$versionlt;/version>
<title>$titlelt;/title>
<authors>Yoav Klein</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
...
Now, this doc says that:
To use these tokens, run nuget pack with the project file rather than just the .nuspec. For example, when using the following command, the $id$ and $version$ tokens in a .nuspec file are replaced with the project's AssemblyName and AssemblyVersion values:
nuget pack MyProject.csproj
My Assembly version is:
# AssemblyInfo.cs
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Now I run nuget pack Logger1.csproj
and I expect the version of the package to be drawn from the AssemblyVersion
of the project, as promised by the docs.
After creating the package, I examine the .nuspec file in the package created:
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Logger1</id>
<version>1.0.0</version>
As you can see, for some reason, it doesn't take the correct value of the AssemblyVersion
which is 1.6.0
, but rather always uses the value 1.0.0
.
Can someone tell me what am I doing wrong?
NuGet Version: 5.8.1.7021
Just to confirm, after building the dll, I can see that the assembly version is 1.6.0:
PS> [Reflection.AssemblyName]::GetAssemblyName("$(pwd)\bin\Debug\Logger1.dll")
Version Name
------- ----
1.6.0.0 Logger1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题看起来很像一个潜在的问题。
我做了更多的测试,经过分析,我发现在打包过程中,总是出现类似
XXXXX is required
这样的错误消息。我确认了好几次,并参考了官方文档,其中提到标记将替换为我的AssemblyInfo.cs
文件中设置的值。例如,如果我按照承诺设置
[assemble: AssemblyCompany("Company")]
,则 $author$ 标记应替换为“Company”,但它没有被替换,而是报告 < code>Authors is required 错误,看起来 nuget.exe 根本没有检查我的AssemblyInfo.cs
文件。然后我找到了这个线程: NuGet 再次抛出异常“需要作者”...忽略 csproj/nuspec 替换令牌。我看到了一种解决方法/解决方案>将下载的nuget.exe文件命名为nuget.exe文件,右键文件>属性>检查
此文件来自另一台计算机,可能会被阻止以帮助保护此计算机。
消息旁边的取消阻止
选项。看来这就是解决方案,让 nuget.exe 正常工作来查找并检查AssemblyInfo.cs
文件,然后替换令牌。简而言之(整个解决方案)
从官网下载nuget.exe,并确保其名称为nuget.exe。然后右键单击 nuget.exe 文件并选择“属性”。切换到常规选项卡,选中
取消阻止
选项。转到您的项目文件夹,先清除项目缓存(删除bin
、obj
文件夹,在 VS 中关闭您的解决方案并删除隐藏的.vs
文件夹中,删除.nuspec
文件和.nupkg
文件),然后在命令提示符中使用nuget.exe spec
生成新的.nuspec
文件,将其编辑为您想要的内容 想。之后运行nuget.exe pack yourproject.csproj
命令行来打包 NuGet 包。简而言之(原因)
在我看来,下载的 nuget.exe 文件被阻止了。
This issue looks quite like a potential issue.
I did more tests and, after analyzing, I saw that, during the packing process, always, there was an error message like
XXXXX is required
. I confirmed several times, and referred to the official documents, which mentioned that the tokens will be replaced with the value which set in myAssemblyInfo.cs
file.For example, if I set
[assembly: AssemblyCompany("Company")]
, as promised, the $author$ token should be replaced with "Company" but it wasn’t replaced, instead it reportedAuthors is required
error, which looks like nuget.exe didn’t check myAssemblyInfo.cs
file at all.I then found this thread: NuGet again throwing exceptions "authors is required"… ignoring csproj/nuspec replacement tokens. And I saw one workaround/solution > name the downloaded nuget.exe file to nuget.exe file and right-click the file > property > check the
Unblock
option besideThis file came from another computer and might be blocked to help protect this computer.
message. And it seems it’s the solution and let nuget.exe work normally to find and checkAssemblyInfo.cs
file then replace the tokens.In short(whole solution)
Download nuget.exe from official website and make sure that its name is nuget.exe. Then right-click the nuget.exe file and choose Properties. Switch to General tab, check the
Unblock
option. Go to your project folder, clear the project cache first(deletebin
,obj
folders, close your solution in VS and delete the hidden.vs
folder, remove the.nuspec
file and.nupkg
file), and then usenuget.exe spec
in command prompt to generate a new.nuspec
file, edit it to what you want. After that runnuget.exe pack yourproject.csproj
command line to pack your NuGet package.In short(reason)
In my opinion, the downloaded nuget.exe file is blocked.