示例#1
0
        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);
        }