I am writing a .NET Core Command Line Application as a CLI for my build system. This part of the build system involves generating a NuGet package from a class library. I am using ProcessStartInfo.cs
and Process.cs
to make a call to nuget.exe
to issue the pack command (nuget.exe
location is in the system PATH
).
dotnet pack
.The issue I am facing is that on my personal machine, when I run my build system CLI, everything works perfectly fine; however, when my build server runs it, the process appears to attempt to start, but then exits without throwing an exception or returning any sort of exit code. Both accounts (Me on my local machine and the account the build server runs under) are local admin accounts.
Cmd.cs (Executes process)
public static class Cmd
{
public static int Execute(string filename, string arguments)
{
var startInfo = new ProcessStartInfo
{
CreateNoWindow = true,
FileName = filename,
Arguments = arguments,
};
using (var process = new Process { StartInfo = startInfo })
{
try
{
process.Start();
process.WaitForExit(30000);
return process.ExitCode;
}
catch (Exception exception)
{
if (!process.HasExited)
{
process.Kill();
}
Console.WriteLine($"Cmd could not execute command {filename} {arguments}:\n{exception.Message}");
return (int)ExitCode.Exception;
}
}
}
}
Package.cs (uses Cmd.cs)
// Some code before this
// The below three variables are generated/provided and are made up here for show
var version = "1.0.0";
var package = $"MyLib.{version}";
var projectPath = "C:\Some\Made\Up\Path";
///////////
// Real code
var tempPath = $"{Path.Combine(Path.GetTempPath(), "NugetPackages")}";
var packagePath = Path.Combine(tempPath, package);
if (!Directory.Exists(tempPath))
{
try
{
Directory.CreateDirectory(tempPath);
}
catch (Exception exception)
{
Console.WriteLine($"Could not create directory in user temp file: {exception.Message}");
return (int) ExitCode.FilePermission;
}
}
var filename = "nuget.exe";
var arguments = $"pack -Version {version} -OutputDirectory {tempPath} -properties Configuration=Release {projectPath}";
var exitCode = Cmd.Execute(filename, arguments);
if (exitCode != 0)
{
Console.WriteLine($"Process failed to execute and exited with exit code: {exitCode}");
return exitCode;
}
Console.WriteLine($"{package} built successfully");
// Some code after this
I modified my code to display all window output and it appears that the same version of NuGet.exe behaves differently on Windows 10 Pro vs Windows Server 2016... not sure why, but on Windows 10 Pro I can use the -Version tag to replace the $version$ token in the .nuspec, but in Windows Server 2016, I cannot do this and have to use a different token (e.g. $package$) and use the -properties switch to replace $package$ with my version... lame sauce!
So, instead of:
nuget.exe pack -Version 1.0.0 -OutputDirectory C:\Somewhere -properties Configuration=Release MyLib
I have to use
nuget.exe pack -OutputDirectory C:\Somwhere -properties "Configuration=Release;package=1.0.0" MyLib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With