public int Execute(CommandLineApplication cmd) { bool force = _force.HasValue(); AssemblyHashAlgorithm hashAlgorithm = ParseAssemblyHashAlgorithm(_hashAlgorithm.ParsedValue); string keyFile = _keyFile.Value; string publicKeyFile = _publicKeyFile.Value; try { if (File.Exists(publicKeyFile) && !force) { throw new FileAlreadyExistsException(publicKeyFile); } StrongNameKey key = _keyLoader.LoadKey(keyFile); byte[] publicKey = key.WithHashAlgorithm(hashAlgorithm) .PublicKey; File.WriteAllBytes(publicKeyFile, publicKey); } catch (Exception error) { cmd.Error.WriteLine("ERROR: {0}", error.Message); return(ExitCodes.FromException(error)); } cmd.Out.WriteLine("Public key written to '{0}'.", publicKeyFile); return(ExitCodes.Success); }
public int Execute(CommandLineApplication cmd) { bool delaySign = _delaySign.HasValue(); bool force = _force.HasValue(); string keyFile = _keyFile.Value; string assemblyFile = _assemblyFile.Value; string outAssemblyFile = !string.IsNullOrEmpty(_outAssemblyFile.Value) ? _outAssemblyFile.Value : null; try { if (File.Exists(outAssemblyFile) && !force) { throw new FileAlreadyExistsException(outAssemblyFile); } if (delaySign) { StrongNamePublicKey publicKey = _keyLoader.LoadPublicKey(keyFile); _signer.DelaySignAssembly(assemblyFile, publicKey, outAssemblyFile); } else { StrongNameKey key = _keyLoader.LoadKey(keyFile); _signer.SignAssembly(assemblyFile, key, outAssemblyFile); } } catch (Exception error) { cmd.Error.WriteLine("ERROR: {0}", error.Message); return(ExitCodes.FromException(error)); } cmd.Out.WriteLine("Assembly '{0}' successfully signed.", outAssemblyFile); return(ExitCodes.Success); }