diff --git a/README.md b/README.md index 44e1cfd..015f1de 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,11 @@ This command has two drawbacks 2. You have to enter PFX password. This password cannot be passed as a parameter which make things complicated in batch scenarios. ## SnInstallPFX utility -I have written a .NET utility that overcomes the aforementioned drawbacks. It computes the container name from the PFX file and accepts the password as a parameter. +I have written a .NET utility that overcomes the aforementioned drawbacks. It computes the container name from the PFX file (if not specified) and accepts the password as a parameter. ``` SnInstallPfx.exe +SnInstallPfx.exe ``` The hash computing is copied from the MSBuild source code on GitHub. diff --git a/src/SnInstallPfx.cs b/src/SnInstallPfx.cs index bf212a0..7cf9d92 100644 --- a/src/SnInstallPfx.cs +++ b/src/SnInstallPfx.cs @@ -12,14 +12,16 @@ public static class SnInstallPfx static int Main(string[] args) { // params and usage - if (args.Length == 0 || args[0] == "?" || args[0] == "-?" || args.Length != 2) + if (args.Length == 0 || args[0] == "?" || args[0] == "-?" || args.Length != 2 || args.Length != 3) { Console.WriteLine("By Honzajscz at 2019"); Console.WriteLine("Installs key pair from into a key container compatible for MSBuild."); Console.WriteLine("This utility is an alternative for command sn.exe -i ."); - Console.WriteLine("It accepts password from command line and automatically generates a container for ."); + Console.WriteLine("It accepts password from command line and automatically generates a container name for if no container name is specified via the argument."); Console.WriteLine(); - Console.WriteLine($"Usage: {Assembly.GetEntryAssembly().GetName().Name}.exe "); + Console.WriteLine("Usage:"); + Console.WriteLine($"{Assembly.GetEntryAssembly().GetName().Name}.exe "); + Console.WriteLine($"{Assembly.GetEntryAssembly().GetName().Name}.exe "); Console.WriteLine(); return -1; @@ -27,8 +29,8 @@ static int Main(string[] args) string pfxPath = args[0]; string pfxPassword = args[1]; + string pfxContainer = args.Length == 3 ? args[2] : ResolveKeySourceTask.ResolveAssemblyKey(pfxPath); - var pfxContainer = ResolveKeySourceTask.ResolveAssemblyKey(pfxPath); if (ResolveKeySourceTask.IsContainerInstalled(pfxContainer)) { //Installs from infile in the specified key container. The key container resides in the strong name CSP. @@ -36,8 +38,8 @@ static int Main(string[] args) Console.Error.WriteLine("To delete the key container run following command from the Developer Command Prompt:"); Console.Error.WriteLine($"sn.exe -d {pfxContainer}"); Console.Error.WriteLine(); - Console.Error.WriteLine($"To list all installed key containers run following command:"); - Console.Error.WriteLine($"certutil -csp \"Microsoft Strong Cryptographic Provider\" -key"); + Console.Error.WriteLine("To list all installed key containers run following command:"); + Console.Error.WriteLine("certutil -csp \"Microsoft Strong Cryptographic Provider\" -key"); return -2; }