WinArgv 1.1.0

dotnet add package WinArgv --version 1.1.0
                    
NuGet\Install-Package WinArgv -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WinArgv" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WinArgv" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="WinArgv" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WinArgv --version 1.1.0
                    
#r "nuget: WinArgv, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=WinArgv&version=1.1.0
                    
Install WinArgv as a Cake Addin
#tool nuget:?package=WinArgv&version=1.1.0
                    
Install WinArgv as a Cake Tool

Build status

nuget.org: petrsnd/WinArgv

WinArgv

Windows command line generation from a standard args array (POSIX argv style)

Background

The .NET Framework's Process.Start() method receives all arguments in a single string to launch an executable. This is the case no matter which overload you call:

Process.Start(String, String)

or, even if you use a ProcessStartInfo:

Process.Start(ProcessStartInfo)

This places the burden on the caller for escaping and quoting to ensure that args array is properly formed for the Main() method of the executable launched by Process.Start().

This seems easy until there are lots of quotes, spaces, and non-standard characters in your arguments. The purpose of this project is to allow the caller to build the array of arguments just as they expect them to be received by the called executable. This library will build the properly escaped and quoted argument string to pass to Process.Start(). It will also generate a ProcessStartInfo with the FileName and Arguments fields filled out, and you can customize the rest from there.

Even though this is a simple library, this isn't a problem that should have to be solved by every developer who would like to create a process.

Example Usage

This library provides a way to build up process arguments in an array, similar to what would be used for execv(). However, the executable should be placed at index 0, so really it is more like what you would see in the argv array in main() on a POSIX system.

var argv = new List<string> {@"C:\bin\grandmaster-flash.exe", "don't push me cuz I'm close to the edge", "I'm trying not to lose my head!"};
// create a ProcessStartInfo
var startInfo = ArgvParser.GetProcessStartInfo(argv);
// or, a commandLine
var cmdLine = ArgvParser.GetCommandLine(argv);
Console.WriteLine(cmdLine.Executable);
Console.WriteLine(cmdLine.Arguments);

The argument string may look very strange, but that is because Windows argument string parsing IS strange. It will always parse out as exactly the list of arguments you wanted to send.

You can clone this code and run the OldFrameworkTest project for an interactive demo.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 150 a month ago
1.1.0-dev-34 137 a month ago
1.1.0-dev-32 86 7 months ago
1.1.0-dev-28 84 7 months ago
1.1.0-dev-25 132 7/5/2023
1.1.0-dev-24 188 6/7/2022
1.1.0-dev-22 258 6/17/2021
1.0.1 110 7 months ago
1.0.0 439 6/17/2021
1.0.0-dev-18 259 6/17/2021
0.9.11 1,235 9/29/2017
0.9.8 1,080 5/8/2017

- Updated Nuget packages and framework targets
- Updated copyrights