public void InstallLatestPackages(ThreadedWaitDialogProgressScope scope, Project project)
 {
     foreach (string packageId in packageIdList)
     {
         scope.Update(
             "Checking Packages",
             $"Checking if package {packageId} is installed",
             $"Checking if package {packageId} is installed",
             true
             );
         if (GlobalServices.InstallerServices.IsPackageInstalled(project, packageId))
         {
             continue;
         }
         try
         {
             scope.Update(
                 "Installing Package",
                 $"Installing latest package {packageId}",
                 $"Installing latest package {packageId}",
                 true
                 );
             GlobalServices.PackageInstaller2.InstallLatestPackage(null, project, packageId, true, false);
         }
         catch (Exception e)
         {
             Debug.Print(e.Message);
         }
     }
 }
        public void AddRequiredReferences(ThreadedWaitDialogProgressScope scope, Project project)
        {
            VSProject vsproject = project.Object as VSProject;

            string[] referenceNames = GetReferences(vsproject).Select(r => r.Name).ToArray();
            foreach (KeyValuePair <string, string> kvp in ReferenceDictionary)
            {
                scope.Update(
                    "Checking Reference",
                    $"Checking if reference {kvp.Key} has resolved",
                    $"Checking if reference {kvp.Key} has resolved",
                    true
                    );
                IEnumerable <string> enumerable = referenceNames;
                if (!enumerable.Contains(kvp.Key))
                {
                    try
                    {
                        scope.Update(
                            "Adding Reference",
                            $"Adding reference {kvp.Key} with path {kvp.Value}",
                            $"Adding reference {kvp.Key} with path {kvp.Value}",
                            true
                            );
                        Reference newreference = vsproject.References.Add(kvp.Value);
                    }
                    catch (Exception e)
                    {
                        Debug.Print(e.Message);
                    }
                }
            }
        }
        private static void GenerateXamlPropertyRuleCore(ThreadedWaitDialogProgressScope scope, ProjectItem folder, string content, string fileName)
        {
            scope.Update("Generating XamlPropertyRule", $"Creating {fileName}", $"Creating {fileName}", true);
            string directory            = folder.FileNames[0];
            string xamlPropertyRulePath = Path.Combine(directory, fileName);
            string codeBehindFilePath   = Path.Combine(directory, $"{fileName}.cs");
            string rootNamespace        = folder.ContainingProject.Properties.Item("DefaultNamespace").Value.ToString();
            string codeBehindContent    = GenerateCodeBehindContent(Path.GetFileNameWithoutExtension(fileName), rootNamespace);

            File.WriteAllText(xamlPropertyRulePath, content);
            scope.Update("Generating XamlPropertyRule CodeBehind", $"Creating {fileName}.cs", $"Creating {fileName}.cs", true);
            File.WriteAllText(codeBehindFilePath, codeBehindContent);
            SetXamlPropertyRuleBuildProperties(folder.ProjectItems.AddFromFile(xamlPropertyRulePath));
        }
        private static void GenerateXamlPropertyRuleProjectItemsSchema(ThreadedWaitDialogProgressScope scope, ProjectItem folder, string content, string fileName)
        {
            scope.Update("Generating XamlPropertyRuleProjectItemsSchema", $"Creating {fileName}", $"Creating {fileName}", true);
            string directory            = folder.FileNames[0];
            string xamlPropertyRulePath = Path.Combine(directory, fileName);

            File.WriteAllText(xamlPropertyRulePath, content);
            SetXamlPropertyRuleProjectItemsSchemaBuildProperties(folder.ProjectItems.AddFromFile(xamlPropertyRulePath));
        }
Exemple #5
0
        public void EnsureReferences(ThreadedWaitDialogProgressScope scope, ReferencesOption option, Project project)
        {
            IEnumerable <MetadataReference>   optionReferences  = GetList(option);
            ImmutableList <MetadataReference> currentReferences = project.MetadataReferences.ToImmutableList();

            foreach (MetadataReference reference in optionReferences)
            {
                scope.Update(
                    "Checking References",
                    $"Checking if reference {reference.Display} has resolved",
                    $"Checking if reference {reference.Display} has resolved",
                    true
                    );
                if (currentReferences.Contains(reference))
                {
                    continue;
                }

                scope.Update(
                    "Adding References",
                    $"Adding reference {reference.Display}",
                    $"Adding reference {reference.Display}"

                    );


                project = project.AddMetadataReference(reference);

                try
                {
                    _workspace.TryApplyChanges(project.Solution);
                }
                catch (Exception e)
                {
                    Debug.Print(e.Message);
                }
            }
        }