Ejemplo n.º 1
0
        public static void GenerateKey(DTE dte, Project project, string destDirectory)
        {
            try
            {
                if (string.IsNullOrEmpty(destDirectory))
                {
                    return;
                }

                //Generate new key
                StatusBar.SetStatusBarValue(dte, Resources.Resource.GeneratingKeyStatusBarMessage);

                string keyFilePath = Path.Combine(destDirectory, Resources.Resource.DefaultKeyName);
                IntPtr buffer      = IntPtr.Zero;

                try
                {
                    uint buffSize;
                    if (0 != StrongNameKeyGen(IntPtr.Zero, 0, out buffer, out buffSize))
                    {
                        Marshal.ThrowExceptionForHR(StrongNameErrorInfo());
                    }
                    if (buffer == IntPtr.Zero)
                    {
                        throw new InvalidOperationException();
                    }

                    var keyBuffer = new byte[buffSize];
                    Marshal.Copy(buffer, keyBuffer, 0, (int)buffSize);
                    File.WriteAllBytes(keyFilePath, keyBuffer);
                }
                finally
                {
                    StrongNameFreeBuffer(buffer);
                }

                //var props = _dte.Properties["CRM Developer Extensions", "General"];
                //string defaultKeyFileName = props.Item("DefaultProjectKeyFileName").Value;

                //foreach (ProjectItem item in project.ProjectItems)
                //{
                //    if (item.Name.ToUpper() != "MYKEY.SNK") continue;

                //    item.Name = defaultKeyFileName + ".snk";
                //    return;
                //}

                project.Properties.Item("SignAssembly").Value = "true";
                project.Properties.Item("AssemblyOriginatorKeyFile").Value = Resources.Resource.DefaultKeyName;
                project.ProjectItems.AddFromFile(keyFilePath);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Resources.Resource.GeneratingKeyFailureMessage + ":  " + ex.Message);
            }
            finally
            {
                dte.StatusBar.Clear();
            }
        }
        public static void InstallPackage(string package, string version, string path)
        {
            try
            {
                if (!string.IsNullOrEmpty(version))
                {
                    version = $"@{version}";
                }

                StatusBar.SetStatusBarValue($"{Resources.Resource.NpmPackageInstallingStatusBarMessage}: {package}{version}");

                var processStartInfo = CreateProcessStartInfo();
                processStartInfo.WorkingDirectory = path;

                var process = Process.Start(processStartInfo);
                if (process == null)
                {
                    MessageBox.Show($"{Resources.Resource.NpmPackageInstallFailureMessage}");
                    return;
                }

                process.StandardInput.WriteLine($"npm install --save {package}{version}");
                process.StandardInput.Flush();
                process.StandardInput.Close();
                process.WaitForExit();

                if (process.ExitCode != 0)
                {
                    MessageBox.Show($"{Resources.Resource.NpmPackageInstallFailureMessage}: {process.StandardError.ReadToEnd()}");
                }
            }
            finally
            {
                StatusBar.ClearStatusBarValue();
            }
        }