简体   繁体   English

为 NuGet nuspec 文件指定 PackageID

[英]Specify PackageID for NuGet nuspec file

I'm writing a deploying app to take my DLL's and create .nuspec files for each, package them, and push out to Artifactory.我正在编写一个部署应用程序来获取我的 DLL 并为每个文件创建 .nuspec 文件,将它们打包,然后推送到 Artifactory。

Trying to use command line in c# to do this.尝试在 c# 中使用命令行来执行此操作。

The problem I'm having is that the DLL's are on a network drive, and calling nuget spec command on the file location uses the full file path as the PackageID which contains invalid characters when trying to pack.我遇到的问题是 DLL 位于网络驱动器上,并且在文件位置调用 nuget spec 命令使用完整文件路径作为 PackageID,其中在尝试打包时包含无效字符。

using (Process myProcess = new Process())
{
  var file = @"\\network-drive\Network-Folder\MyDLLs\Test.dll";
  myProcess.StartInfo.UseShellExecute = false;
  myProcess.StartInfo.FileName = "CMD.exe";
  myProcess.StartInfo.Arguments = string.Format("/c nuget spec \"{0}\"", file);
  myProcess.StartInfo.CreateNoWindow = false;
  myProcess.StartInfo.RedirectStandardOutput = true;
  myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  myProcess.Start();
  myProcess.WaitForExit();
}

this results in这导致

<?xml version="1.0"?>
<package >
  <metadata>
    <id>\\network-drive\Network-Folder\MyDLLs\Test.dll</id>
    <version>1.0.0</version>
    ....

How can I specify the packageID to something like My.TestDLL?如何将 packageID 指定为 My.TestDLL 之类的内容?

I tried doing something like我尝试做类似的事情

nuget spec My.TestDLL -AssemblyPath \\network-drive\Network-Folder\MyDLLs\Test.dll

But have no idea where the nuspec file went as it was not in the directory.但是不知道 nuspec 文件去了哪里,因为它不在目录中。

You are creating a new command line to use and then passing the command to it.您正在创建一个要使用的新命令行,然后将命令传递给它。 Think about opening up a new command window.考虑打开一个新的命令窗口。 Where does it default to?它默认在哪里?

If you didn't already have NuGet stored in the environment variables (assumption), you would have to either specify the full path to NuGet.exe or set the working directory to the folder which has the NuGet executable.如果您尚未将 NuGet 存储在环境变量中(假设),则必须指定 NuGet.exe 的完整路径或将工作目录设置为包含 NuGet 可执行文件的文件夹。 Since you are not doing either, the command window is using the default location to create that .nuspec file.由于您没有执行任何操作,因此命令窗口使用默认位置来创建该 .nuspec 文件。

I would set the working directory for the ProcessStartInfo object.我将为ProcessStartInfo对象设置工作目录。 When you set the working directory, you are specifying where you want NuGet to create the file on disc.设置工作目录时,就是指定希望 NuGet 在磁盘上创建文件的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM