// Methods
        public override void Execute()
        {
            DTE dte = base.GetService <DTE>();

            string solutionDirectory = Path.GetDirectoryName((string)dte.Solution.Properties.Item("Path").Value);
            string targetPath        = Path.Combine(solutionDirectory, this.RelativePath);
            string targetDir         = Path.GetDirectoryName(targetPath);

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }
            using (StreamWriter writer = new StreamWriter(targetPath, false, new UTF8Encoding(true, true)))
            {
                writer.WriteLine(this.content);
            }

            SolutionFolder sf = DteHelper.FindSolutionFolderByPath(dte.Solution, Path.GetDirectoryName(this.RelativePath));

            if (null != sf)
            {
                sf.Parent.ProjectItems.AddFromFile(targetPath);
            }
            else
            {
                DteHelper.SelectSolution(dte);
                ProjectItem pi = dte.ItemOperations.AddExistingItem(targetPath);
            }
            dte.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
        }
        /// <summary>
        /// Executes the action.
        /// </summary>
        public override void Execute()
        {
            EnvDTE.DTE vs = this.GetService <EnvDTE.DTE>(true);
            string     keyFilePath;

            if (this.KeyFile == null)
            {
                string solutionPath = (string)vs.Solution.Properties.Item("Path").Value;
                string solutionDir  = Path.GetDirectoryName(solutionPath);
                keyFilePath = Path.Combine(solutionDir, this.Name + ".snk");

                // Find the .NET SDK directory to execute the sn.exe command.
                RegistryKey regKeySN = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Microsoft SDKs\Windows\v8.1A");
                string      sdkDir   = Path.Combine(regKeySN.GetValue(@"InstallationFolder").ToString(), "bin", "NETFX 4.5.1 Tools");
                if (!Directory.Exists(sdkDir))
                {
                    throw new InvalidOperationException("Could not find the Visual Studio SDK directory to execute the sn.exe command. Searching folder " + sdkDir);
                }
                string snPath = Path.Combine(sdkDir, "sn.exe");
                if (!File.Exists(snPath))
                {
                    throw new InvalidOperationException("Could not find the sn.exe command in the Visual Studio SDK directory. Searching for " + snPath);
                }

                // Make sure the directory exists.
                Directory.CreateDirectory(Path.GetDirectoryName(keyFilePath));

                // Launch the process and wait until it's done (with a 10 second timeout).
                ProcessStartInfo startInfo = new ProcessStartInfo(snPath, string.Format("-k \"{0}\"", keyFilePath));
                startInfo.CreateNoWindow  = true;
                startInfo.UseShellExecute = false;
                Process snProcess = Process.Start(startInfo);
                snProcess.WaitForExit(10000);

                // Add the key file to the Solution Items.
                DteHelper.SelectSolution(vs);
                vs.ItemOperations.AddExistingItem(keyFilePath);

                // The AddExistingItem operation also shows the item in a new window, close that.
                vs.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
            }
            else
            {
                keyFilePath = this.keyFile;
            }

            //set the assemblykeyfile property for every Project
            foreach (EnvDTE.Project project in vs.Solution.Projects)
            {
                if (project.Properties != null)
                {
                    if (project.Kind == BusinessComponents.Constants.ClassLibraryProjectType)
                    {
                        project.Properties.Item("SignAssembly").Value = true;
                        project.Properties.Item("AssemblyOriginatorKeyFile").Value = keyFilePath;
                    }
                }
            }
        }
예제 #3
0
        public override void Execute()
        {
            EnvDTE.DTE dte = this.GetService <EnvDTE.DTE>(true);


            try
            {
                IVsSolutionPersistence pers = this.GetService <IVsSolutionPersistence>(true);

                //pers.LoadPackageUserOpts(
            }
            catch (Exception)
            {
            }

            string template = this.SourceFileName;

            if (Content != "")
            {
                template = Path.GetTempFileName();
                using (StreamWriter writer = new StreamWriter(template, false))
                {
                    writer.WriteLine(Content);
                }
            }

            string templateBasePath = GetTemplateBasePath();

            if (!Path.IsPathRooted(template))
            {
                template = Path.Combine(templateBasePath, template);
            }

            template = new FileInfo(template).FullName;

            string solutionPath = (string)dte.Solution.Properties.Item("Path").Value;
            string solutionDir  = Path.GetDirectoryName(solutionPath);
            string keyFilePath  = Path.Combine(solutionDir, this.TargetFileName);

            File.Copy(template, keyFilePath);

            try
            {
                Helpers.LogMessage(dte, this, keyFilePath + ": File added");

                DteHelper.SelectSolution(dte);
                dte.ItemOperations.AddExistingItem(keyFilePath);
                dte.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
            }
            catch (Exception ex)
            {
                Helpers.LogMessage(dte, this, ex.ToString());
            }
        }
        /// <summary>
        /// Executes the action.
        /// </summary>
        public override void Execute()
        {
            if (this.KeyFile == null)
            {
                EnvDTE.DTE vs           = this.GetService <EnvDTE.DTE>(true);
                string     solutionPath = (string)vs.Solution.Properties.Item("Path").Value;
                string     solutionDir  = Path.GetDirectoryName(solutionPath);

                // Changed by GOP. Relative path instead of absolute.
                string keyFileName = this.Name + ".snk";
                string keyFilePath = Path.Combine(solutionDir, keyFileName);

                // Find the .NET SDK directory to execute the sn.exe command.
                //string visualStudioDir = Path.GetDirectoryName(vs.Application.FileName);
                //string sdkDir = Path.Combine(visualStudioDir, @"..\..\SDK\v2.0\Bin");
                //string snPath = Path.Combine(sdkDir, "sn.exe");
                //if (!File.Exists(snPath))
                //{
                //  throw new InvalidOperationException("Could not find the Visual Studio SDK directory to execute the sn.exe command.");
                //}

                // Find the .NET SDK directory to execute the sn.exe command.
                RegistryKey regKeySN = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Microsoft SDKs\Windows\v6.0A\WinSDKNetFxTools");
                if (regKeySN == null)
                {
                    // Second try
                    regKeySN = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SDKs\.NETFramework\v2.0");
                }
                string sdkDir = regKeySN.GetValue(@"InstallationFolder").ToString() + "bin";
                if (!Directory.Exists(sdkDir))
                {
                    throw new InvalidOperationException("Could not find the Visual Studio SDK directory to execute the sn.exe command. Searching folder " + sdkDir);
                }
                string snPath = Path.Combine(sdkDir, "sn.exe");
                if (!File.Exists(snPath))
                {
                    throw new InvalidOperationException("Could not find the sn.exe command in the Visual Studio SDK directory. Searching for " + snPath);
                }


                // Make sure the directory exists.
                Directory.CreateDirectory(Path.GetDirectoryName(keyFilePath));

                // Launch the process and wait until it's done (with a 10 second timeout).
                ProcessStartInfo startInfo = new ProcessStartInfo(snPath, string.Format("-k \"{0}\"", keyFilePath));
                startInfo.CreateNoWindow  = true;
                startInfo.UseShellExecute = false;
                Process snProcess = Process.Start(startInfo);
                snProcess.WaitForExit(10000);

                // Add the key file to the Solution Items.
                DteHelper.SelectSolution(vs);
                vs.ItemOperations.AddExistingItem(keyFilePath);

                // The AddExistingItem operation also shows the item in a new window, close that.
                vs.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);

                //set the assemblykeyfile property for every BizTalk Project
                foreach (EnvDTE.Project project in vs.Solution.Projects)
                {
                    if (project.Properties != null)
                    {
                        if (project.Kind == BusinessComponents.Constants.BizTalkProjectType)
                        {
                            // Changed by GOP. Relative path instead of absolute.
                            ((System.Collections.Hashtable)(project.Properties.Item(5).Value))["AssemblyKeyFile"] = @"..\\..\\..\\" + keyFileName;
                        }
                        else if (project.Kind == BusinessComponents.Constants.ClassLibraryProjectType)
                        {
                            // Changed by GOP. Relative path instead of absolute.
                            project.Properties.Item("SignAssembly").Value = true;
                            project.Properties.Item("AssemblyOriginatorKeyFile").Value = @"..\\" + keyFileName;
                        }
                    }
                }
            }
        }