从“nuget pack"命令中检索创建的 NuGet 包文件名? [英] Retrieve created NuGet package filename from 'nuget pack' command?
问题描述
我正在编写一个脚本,该脚本将自动打包 Nuget 文件并将其发布到我的私有存储库(文件共享)和私有符号服务器(在本地主机上).
I'm writing a script that will automatically pack and publish Nuget files to my private repository (a fileshare) and a private symbol server (on localhost).
当我在 Powershell 中运行 nuget pack
时,我得到一个字符串输出,其中包含 nuget 和符号包的文件位置,但据我所知,无法以编程方式 无需解析字符串即可获取这些路径.包版本是由.csproj本身决定的,所以我不一定知道文件名中会放哪个版本.
When I run nuget pack
in Powershell I get a string output that contains the file location of both the nuget and symbol package, but as far as I can tell there's no way to programmatically get those paths without parsing the string. The package version is determined by the .csproj itself, so I don't necessarily know which version will be placed in the filename.
这是 pack 命令的输出:
Here's the output from the pack command:
Attempting to build package from 'MyProject.csproj'.
Building project 'C:\Users\me\prg\MyProject.csproj' for target framework '.NETFramework,Version=v4.0'.
Packing files from 'C:\Users\me\prg\bin\Release'.
Using 'Myproject.nuspec' for metadata.
Successfully created package 'C:\nuget\MyProject.1.0.0.0.nupkg'.
Attempting to build symbols package for 'MyProject.csproj'.
Building project 'C:\Users\me\prg\MyProject.csproj' for target framework '.NETFramework,Version=v4.0'.
Packing files from 'C:\Users\me\prg\bin\Release'.
Using 'MyProject.nuspec' for metadata.
Successfully created package 'C:\nuget\Myproject.1.0.0.0.symbols.nupkg'.
我应该硬着头皮写一些正则表达式来解析成功创建的包"行吗?
Should I just bite the bullet and write some regex to parse out the "successfully created package" lines?
推荐答案
默认情况下 nuget pack
会将创建的包输出到当前目录.您可以通过指定 OutputDirectory
选项来覆盖它.我不清楚您从哪里运行 nuget
命令(无论是在 C:\Users\me\prg\、C:\nuget\ 或其他地方),所以您可能已经知道这一点,但它可以为您提供另一种选择:
By default nuget pack
will output the created packages to the current directory. You can override this by specifying the OutputDirectory
option. It is not clear to me from where you run the nuget
command (be it from within C:\Users\me\prg\, C:\nuget\, or somewhere else), so you might already know this, but it can offer you an alternative option:
您可以为自己创建一个临时目录(例如 C:\nuget\temp\),您可以将其指定为您的 OutputDirectory
选项.如果你在你的脚本中确保在你运行 nuget pack
之前这个目录是空的,你可以简单地将 *.nupkg 复制到你的文件共享(然后将它移动到C:\nuget\,如果需要).
You can create yourself a temporary directory (e.g. C:\nuget\temp\), which you can specify as your OutputDirectory
option. If you then in your script make sure that this directory is empty before you run nuget pack
, your can simply copy *.nupkg to your fileshare (and then afterwards move it to C:\nuget\, if that is required).
这篇关于从“nuget pack"命令中检索创建的 NuGet 包文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!