private void EnsureGroupsCreated()
        {
            if (_autoPackageVersions == null)
            {
                _autoPackageVersions       = _document.AddPropertyGroup();
                _autoPackageVersions.Label = AutoPackageVersionsLabel;
            }

            if (_pinnedPackageVersions == null)
            {
                _pinnedPackageVersions       = _document.AddPropertyGroup();
                _pinnedPackageVersions.Label = PinnedPackageVersionsLabel;
            }
        }
Ejemplo n.º 2
0
        private void GenerateAndAddLegacyConfigurationPropertyGroup()
        {
            ProjectPropertyGroupElement group = Xml.AddPropertyGroup();

            group.AddProperty("ProjectGuidString", Guid.NewGuid().ToString("B").ToUpper());
            group.AddProperty("ProjectTypeGuids", VsProjectTypeGuids.LegacyProjectGuid);
        }
Ejemplo n.º 3
0
        public override void Process(
            string sourcePath,
            ProjectRootElement project,
            Dictionary <string, ProjectPropertyGroupElement> groups
            )
        {
            ProjectPropertyGroupElement globals;

            if (!groups.TryGetValue("Globals", out globals))
            {
                globals = project.AddPropertyGroup();
            }

            AddOrSetProperty(globals, "StartupFile", "manage.py");
            AddOrSetProperty(globals, "ProjectTypeGuids", "{5F0BE9CA-D677-4A4D-8806-6076C0FAAD37};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52}");
            AddOrSetProperty(globals, "LaunchProvider", "Django launcher");
            AddOrSetProperty(globals, "WebBrowserUrl", "http://localhost");

            var settingsFilePath = PathUtils.FindFile(sourcePath, "settings.py", depthLimit: 1);

            if (File.Exists(settingsFilePath))
            {
                var packageName = PathUtils.GetLastDirectoryName(settingsFilePath);
                AddOrSetProperty(globals, "DjangoSettingsModule", "{0}.settings".FormatInvariant(packageName));
            }

            project.AddImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Django.targets");

            GenericWebProjectCustomization.AddWebProjectExtensions(project);
        }
        public void MigratingScriptsWithMultipleCommandsCreatesExecTaskForEach(string scriptName)
        {
            var scriptMigrationRule = new MigrateScriptsRule();
            ProjectRootElement          mockProj            = ProjectRootElement.Create();
            ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();

            var commands       = new[] { "fakecommand1", "fakecommand2", "mockcommand3" };
            var commandsInTask = commands.ToDictionary(c => c, c => false);

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                commonPropertyGroup,
                commands,
                scriptName,
                IsMultiTFM);

            foreach (var task in target.Tasks)
            {
                var taskCommand = task.GetParameter("Command");
                var originalCommandCandidates = commands.Where(c => taskCommand.Contains(c));
                originalCommandCandidates.Count().Should().Be(1);

                var command = originalCommandCandidates.First();
                commandsInTask[command]
                .Should().Be(false, "Expected to find each element from commands Array once");

                commandsInTask[command] = true;
            }

            commandsInTask.All(commandInTask => commandInTask.Value)
            .Should()
            .BeTrue("Expected each element from commands array to be found in a task");
        }
Ejemplo n.º 5
0
        public void Migrated_ScriptSet_has_two_MigratedScriptExtensionProperties_for_each_script(string scriptName)
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands      = new string[] { "compile:FullTargetFramework", "compile:Configuration" };
            var propertyGroup = mockProj.AddPropertyGroup();
            var target        = scriptMigrationRule.MigrateScriptSet(mockProj, propertyGroup, commands,
                                                                     scriptName);

            Console.WriteLine(string.Join(";", propertyGroup.Properties.Select(n => n.Name)));
            propertyGroup.Properties.Count().Should().Be(commands.Length * 2);

            var count = 0;

            foreach (var command in commands)
            {
                count += 1;
                var scriptExtensionProperties =
                    propertyGroup.Properties.Where(p => p.Name.Contains($"MigratedScriptExtension_{scriptName}_{count}")).ToArray();

                scriptExtensionProperties.All(p => p.Value == ".sh" || p.Value == ".cmd").Should().BeTrue();
                scriptExtensionProperties.Count().Should().Be(2);
            }
        }
Ejemplo n.º 6
0
        private void AssertInputs(string ruleSetPath, IList <string> expectedInputs)
        {
            ProjectRootElement projectRootElement = ProjectRootElement.Create(Path.Combine(_rootDir, "project.proj"));

            if (ruleSetPath != null)
            {
                ProjectPropertyGroupElement propertyGroup = projectRootElement.AddPropertyGroup();
                projectRootElement.AddProperty(CodeAnalysisRuleSetPredictor.CodeAnalysisRuleSetPropertyName, ruleSetPath);
            }

            var projectInstance = TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement);

            var expectedInputFiles = expectedInputs?
                                     .Select(input => new PredictedItem(input, nameof(CodeAnalysisRuleSetPredictor)))
                                     .ToArray();

            _predictor
            .GetProjectPredictions(projectInstance)
            .AssertPredictions(
                projectInstance,
                expectedInputFiles,
                null,
                null,
                null);
        }
        public void MigratedScriptSetHasExecAndReplacesVariables(string scriptName)
        {
            var scriptMigrationRule = new MigrateScriptsRule();
            ProjectRootElement          mockProj            = ProjectRootElement.Create();
            ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();

            var commands = new[] { "%compile:FullTargetFramework%", "%compile:Configuration%" };

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                commonPropertyGroup,
                commands,
                scriptName,
                IsMultiTFM);

            target.Tasks.Count().Should().Be(commands.Length);

            foreach (var task in target.Tasks)
            {
                var taskCommand  = task.GetParameter("Command");
                var commandIndex = Array.IndexOf(commands, taskCommand);

                commandIndex.Should().Be(
                    -1,
                    "Expected command array elements to be replaced by appropriate msbuild properties");
            }
        }
Ejemplo n.º 8
0
            private ProjectRootElement CreateProject()
            {
                Microsoft.Build.Evaluation.Project project = null;
                try
                {
                    project = Microsoft.Expression.Project.Build.BuildManager.GetProject(DocumentReference.Create(this.originalProjectFilePath));
                }
                catch (ArgumentException argumentException)
                {
                }
                ProjectRootElement projectRootElement = ProjectRootElement.Create();

                projectRootElement.ToolsVersion = "4.0";
                this.AddBuildProperties(projectRootElement, project);
                projectRootElement.AddItemGroup();
                projectRootElement.AddPropertyGroup();
                projectRootElement.AddProperty("IntermediateOutputPath", Microsoft.Expression.Framework.Documents.PathHelper.GetDirectoryNameOrRoot(this.xamlPath));
                this.AddAssemblyReferences(projectRootElement, project);
                this.AddImports(projectRootElement, project);
                if (!this.IsSilverlightApplication(project))
                {
                    this.AddWpfImports(projectRootElement);
                }
                projectRootElement.AddItem("Page", this.xamlPath);
                string str = Microsoft.Expression.Framework.Documents.PathHelper.ResolveCombinedPath(Microsoft.Expression.Framework.Documents.PathHelper.GetDirectoryNameOrRoot(this.xamlPath), "MarkupCompileAssembly.proj");

                projectRootElement.Save(str);
                return(projectRootElement);
            }
Ejemplo n.º 9
0
        private static ProjectInstance CreateTestProjectInstance(string fileName, bool hasProjectReferences = true, bool isEnabled = true)
        {
            ProjectRootElement projectRootElement = ProjectRootElement.Create($@"ServiceFabricApp\{fileName}");

            // These are generally set in Microsoft.VisualStudio.Azure.Fabric.Application.targets
            ProjectPropertyGroupElement propertyGroup = projectRootElement.AddPropertyGroup();

            propertyGroup.AddProperty(ServiceFabricServiceManifestPredictor.ApplicationPackageRootFolderPropertyName, "ApplicationPackageRoot");
            propertyGroup.AddProperty(ServiceFabricServiceManifestPredictor.ServicePackageRootFolderPropertyName, "PackageRoot");
            if (isEnabled)
            {
                propertyGroup.AddProperty(ServiceFabricServiceManifestPredictor.UpdateServiceFabricApplicationManifestEnabledPropertyName, "true");
            }

            if (hasProjectReferences)
            {
                ProjectItemGroupElement itemGroup = projectRootElement.AddItemGroup();
                itemGroup.AddItem(ServiceFabricServiceManifestPredictor.ProjectReferenceItemName, @"..\Service1\Service1.csproj");
                itemGroup.AddItem(ServiceFabricServiceManifestPredictor.ProjectReferenceItemName, @"..\Service2\Service2.csproj");
            }

            // Extra service manifests, and some extraneous files too
            Directory.CreateDirectory(@"ServiceFabricApp\ApplicationPackageRoot");
            File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\{ServiceFabricServiceManifestPredictor.ServiceManifestFileName}", "SomeContent"); // Not in a subdir, should not get picked up
            File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\extraneous.txt", "SomeContent");
            Directory.CreateDirectory(@"ServiceFabricApp\ApplicationPackageRoot\Foo");
            File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\Foo\{ServiceFabricServiceManifestPredictor.ServiceManifestFileName}", "SomeContent");
            File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\Foo\extraneous.txt", "SomeContent");
            Directory.CreateDirectory(@"ServiceFabricApp\ApplicationPackageRoot\Bar");
            File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\Bar\{ServiceFabricServiceManifestPredictor.ServiceManifestFileName}", "SomeContent");
            File.WriteAllText($@"ServiceFabricApp\ApplicationPackageRoot\Bar\extraneous.txt", "SomeContent");

            return(TestHelpers.CreateProjectInstanceFromRootElement(projectRootElement));
        }
Ejemplo n.º 10
0
        static ProjectPropertyGroupElement CreatePropertyGroupChoice(ProjectRootElement root,
                                                                     string condition,
                                                                     bool unsafeMode, string outputPath, bool optimize,
                                                                     bool debugSymbol, string debugType, string constants
                                                                     )
        {
            ProjectPropertyGroupElement group = root.AddPropertyGroup();

            group.Condition = condition;
            if (unsafeMode)
            {
                group.AddProperty("AllowUnsafeBlocks", "true");
            }
            group.AddProperty("ErrorReport", "prompt");
            group.AddProperty("WarningLevel", "4");
            group.AddProperty("OutputPath", outputPath); //,eg  @"bin\Debug\"
            group.AddProperty("Optimize", optimize ? "true" : "false");
            group.AddProperty("DebugType", debugType);
            if (debugSymbol)
            {
                group.AddProperty("DebugSymbols", "true");
            }
            group.AddProperty("DefineConstants", constants); //eg DEBUG; TRACE
            return(group);
        }
        /// <summary>
        /// copy properties from g into a new property group for newConfiguration and newPlatform
        /// </summary>
        void CopyProperties(ProjectRootElement project, ProjectPropertyGroupElement g, ConfigurationAndPlatform newConfig)
        {
            ProjectPropertyGroupElement ng = project.AddPropertyGroup();

            ng.Condition = newConfig.ToCondition();
            foreach (var p in g.Properties)
            {
                ng.AddProperty(p.Name, p.Value).Condition = p.Condition;
            }
        }
Ejemplo n.º 12
0
        public void Migrating_post_scripts_populates_AfterTargets_with_appropriate_target(string scriptName, string targetName)
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();
            var commands = new[] { "fakecommand" };

            var target = scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, scriptName);

            target.AfterTargets.Should().Be(targetName);
        }
Ejemplo n.º 13
0
        private static void InitializeCPSClassLibraryConfigurationProperties(
            ProjectRootElement root, string assemblyName, string rootNamespace, string outputType, string targetFramework)
        {
            ProjectPropertyGroupElement group = root.AddPropertyGroup();

            group.Label = "Configuration";
            group.AddProperty("AssemblyName", assemblyName);
            group.AddProperty("RootNamespace", rootNamespace);
            group.AddProperty("OutputType", outputType);
            group.AddProperty("TargetFramework", targetFramework);
        }
Ejemplo n.º 14
0
        public void Migrating_scripts_creates_target_with_IsCrossTargettingBuild_not_equal_true_Condition()
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands = new[] { "compile:FullTargetFramework", "compile:Configuration" };

            var target = scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, "prepublish");

            target.Condition.Should().Be(" '$(IsCrossTargetingBuild)' != 'true' ");
        }
Ejemplo n.º 15
0
        protected override void UpgradeProject(ref ProjectRootElement projectXml, ref ProjectRootElement userProjectXml, Action <__VSUL_ERRORLEVEL, string> log)
        {
            var envVarsProp = projectXml.Properties.FirstOrDefault(p => p.Name == NodejsConstants.EnvironmentVariables);

            if (envVarsProp != null)
            {
                var globals = projectXml.PropertyGroups.FirstOrDefault() ?? projectXml.AddPropertyGroup();
                AddOrSetProperty(globals, NodejsConstants.Environment, envVarsProp.Value.Replace(";", "\r\n"));
                envVarsProp.Parent.RemoveChild(envVarsProp);
                log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, SR.GetString(SR.UpgradedEnvironmentVariables));
            }
        }
Ejemplo n.º 16
0
        public void Migrating_scripts_throws_on_invalid_ScriptSet()
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands = new string[] { "fakecommand" };

            Action action = () => scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, "invalidScriptSet");

            action.ShouldThrow <MigrationException>()
            .WithMessage("MIGRATE1019::Unsupported Script Event Hook: invalidScriptSet is an unsupported script event hook for project migration");
        }
        public void Generate(string outputPath, string propertyVersionNamePrefix, string propertyPathNamePrefix, PackageRestoreData restoreData)
        {
            // Delete an existing file in case there are no properties generated and we don't end up saving the file
            //
            if (File.Exists(outputPath))
            {
                Retry(() => File.Delete(outputPath), TimeSpan.FromMilliseconds(500));
            }

            ProjectRootElement          project       = ProjectRootElement.Create();
            ProjectPropertyGroupElement propertyGroup = project.AddPropertyGroup();

            propertyGroup.SetProperty("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)");

            ProjectItemGroupElement itemGroup = project.AddItemGroup();

            bool anyPropertiesCreated = false;

            foreach (string packageConfigPath in _packageConfigPaths)
            {
                _logger.LogMessage(MessageImportance.Low, $"Parsing '{packageConfigPath}'");

                IEnumerable <PackageIdentityWithPath> parsedPackages = null;

                INuGetPackageConfigParser configParser = null;

                // A bug in nuget sometimes causes "NuGet.Configuration.NuGetConfigurationException: Unexpected failure reading NuGet.Config." when multiple instances are running in parrallel such as in the quickbuild scenario.
                Retry(() => configParser = _configParsersLazy.Value.FirstOrDefault(i => i.TryGetPackages(packageConfigPath, restoreData, out parsedPackages)), TimeSpan.FromMilliseconds(1000));

                if (configParser != null && parsedPackages != null)
                {
                    anyPropertiesCreated = true;

                    foreach (PackageIdentityWithPath packageInfo in parsedPackages)
                    {
                        propertyGroup.SetProperty($"{propertyPathNamePrefix}{packageInfo.Id.Replace(".", "_")}", $"{packageInfo.FullPath}");

                        propertyGroup.SetProperty($"{propertyVersionNamePrefix}{packageInfo.Id.Replace(".", "_")}", $"{packageInfo.Version.ToString()}");

                        // Consider adding item metadata of packageid and version for ease of consumption of this property.
                        itemGroup.AddItem("CBTNuGetPackageDir", packageInfo.FullPath);
                    }
                }
            }

            // Don't save the file if no properties were created.  In Visual Studio design time builds, this can be called multiple times until there are finally
            // properties that can be created.  If we generate an empty file, it won't get regenerated once there are properties to create.
            //
            if (anyPropertiesCreated)
            {
                Retry(() => project.Save(outputPath), TimeSpan.FromMilliseconds(500));
            }
        }
        public void WriteDirectoryBuildProps(ISolutionOptions options)
        {
            string strongNameKeyDirectory = Path.Combine(options.RepositoryDirectory, "build\\strong name keys\\");

            string strongNameKeyFile = Path.Combine(strongNameKeyDirectory, $"{options.SolutionName}SharedKey.snk");

            Directory.CreateDirectory(strongNameKeyDirectory);


            ProjectRootElement root = ProjectRootElement.Create(NewProjectFileOptions.None);

            ProjectPropertyGroupElement p0 = root.AddPropertyGroup();

            p0.AddProperty("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)");

            ProjectPropertyGroupElement p1 = root.AddPropertyGroup();

            p1.AddDefaultProperty("DisableStandardFrameworkResolution", "false");
            p1.AddDefaultProperty("AppendTargetFrameworkToOutputDirectory", "false");

            ProjectPropertyGroupElement p3 = root.AddPropertyGroup();

            p3.AddProperty("SolutionDir", "$(MSBuildThisFileDirectory)");
            p3.AddProperty("RepositoryDirectory", "$([System.IO.Path]::GetFullPath('$(SolutionDir)..\\'))");
            p3.AddDefaultProperty("OutputPath", @"$([System.IO.Path]::GetFullPath('$(RepositoryDirectory)bin\$(Configuration)\$(MSBuildProjectName)\'))");
            p3.AddDefaultProperty("IntermediateOutputPath", @"$([System.IO.Path]::GetFullPath('$(RepositoryDirectory)bin\obj\$(MSBuildProjectName)\$(Configuration)\'))");


            StrongNameKeyInfo           snk = StrongNameKeyManager.GenerateStrongNameKeyInfo();
            ProjectPropertyGroupElement signingProperties = root.AddPropertyGroup();

            signingProperties.AddDefaultProperty("SignAssembly", "true");
            signingProperties.AddDefaultProperty("AssemblyOriginatorKeyFile", "$(RepositoryDirectory)build\\strong name keys\\$(SolutionName)SharedKey.snk");
            signingProperties.AddDefaultProperty("PublicKey", snk.PublicKey);
            signingProperties.AddDefaultProperty("PublicKeyToken", snk.PublicKeyToken);

            File.WriteAllBytes(strongNameKeyFile, snk.RawBytes);

            root.Save(options.DirectoryBuildPropsPath);
        }
Ejemplo n.º 19
0
        private static void InitializeLegacyVSIXConfigurationProperties(
            ProjectRootElement root, string assemblyName, string rootNamespace, string outputType, string targetFramework, string projectGuid)
        {
            ProjectPropertyGroupElement group = root.AddPropertyGroup();

            group.Label = "Configuration";
            group.AddProperty("ProjectGuid", projectGuid);
            group.AddProperty("ProjectTypeGuids", VsProjectTypeGuids.ExtensibilityFlavorProjectGuid);
            group.AddProperty("AssemblyName", assemblyName);
            group.AddProperty("RootNamespace", rootNamespace);
            group.AddProperty("OutputType", outputType);
            group.AddProperty("TargetFrameworkVersion", targetFramework);
        }
Ejemplo n.º 20
0
        private static void ProcessImportsFrom21b(ProjectRootElement projectXml, Action <__VSUL_ERRORLEVEL, string> log)
        {
            var bottleImports = projectXml.Imports.Where(p => p.Project.Equals(Ptvs21BetaBottleTargets, StringComparison.OrdinalIgnoreCase)).ToList();
            var flaskImports  = projectXml.Imports.Where(p => p.Project.Equals(Ptvs21BetaFlaskTargets, StringComparison.OrdinalIgnoreCase)).ToList();

            foreach (var import in bottleImports.Concat(flaskImports))
            {
                import.Project = WebTargets;
            }

            if (bottleImports.Any())
            {
                var globals = projectXml.PropertyGroups.FirstOrDefault() ?? projectXml.AddPropertyGroup();
                AddOrSetProperty(globals, "PythonDebugWebServerCommandArguments", "--debug $(CommandLineArguments)");
                AddOrSetProperty(globals, "PythonWsgiHandler", "{StartupModule}.wsgi_app()");
                log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, Strings.UpgradedBottleImports);
            }
            if (flaskImports.Any())
            {
                var globals = projectXml.PropertyGroups.FirstOrDefault() ?? projectXml.AddPropertyGroup();
                AddOrSetProperty(globals, "PythonWsgiHandler", "{StartupModule}.wsgi_app");
                log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, Strings.UpgradedFlaskImports);
            }

            var commonPropsImports = projectXml.Imports.Where(p => p.Project.Equals(CommonProps, StringComparison.OrdinalIgnoreCase)).ToList();

            foreach (var p in commonPropsImports)
            {
                projectXml.RemoveChild(p);
                log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, Strings.UpgradedRemoveCommonProps);
            }

            if (projectXml.Imports.Count == 1 && projectXml.Imports.First().Project.Equals(CommonTargets, StringComparison.OrdinalIgnoreCase))
            {
                projectXml.RemoveChild(projectXml.Imports.First());
                projectXml.AddImport(PtvsTargets);
                log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, Strings.UpgradedRemoveCommonTargets);
            }
        }
Ejemplo n.º 21
0
        public void SetCondition()
        {
            ProjectRootElement project = ProjectRootElement.Create();

            project.AddPropertyGroup();
            Helpers.ClearDirtyFlag(project);

            ProjectPropertyGroupElement propertyGroup = Helpers.GetFirst(project.PropertyGroups);

            propertyGroup.Condition = "c";

            Assert.Equal("c", propertyGroup.Condition);
            Assert.Equal(true, project.HasUnsavedChanges);
        }
Ejemplo n.º 22
0
        public override void Run()
        {
            Log.LogMessage("Generating module build package imports");

            ProjectRootElement propsProject   = ProjectRootElement.Create(PropsFile);
            ProjectRootElement targetsProject = ProjectRootElement.Create(TargetsFile);

            ProjectPropertyGroupElement propertyGroup = propsProject.AddPropertyGroup();

            foreach (BuildPackageInfo buildPackageInfo in ModulePaths.Select(BuildPackageInfo.FromModulePath).Where(i => i != null))
            {
                if (buildPackageInfo.PropsPath == null && buildPackageInfo.TargetsPath == null)
                {
                    Log.LogMessage(MessageImportance.Low, $"  Skipping '{buildPackageInfo.Id}' because it is not a standard NuGet build package.");
                    continue;
                }

                // If this is a cbt module do not auto import props or targets.
                if (File.Exists(Path.Combine(Path.GetDirectoryName(buildPackageInfo.PropsPath ?? buildPackageInfo.TargetsPath), "module.config")))
                {
                    Log.LogMessage(MessageImportance.Low, $"  Skipping '{buildPackageInfo.Id}' because it is a CBT Module.");
                    continue;
                }

                ProjectPropertyElement enableProperty = propertyGroup.AddProperty(buildPackageInfo.EnablePropertyName, "false");
                enableProperty.Condition = $" '$({buildPackageInfo.EnablePropertyName})' == '' ";

                ProjectPropertyElement runProperty = propertyGroup.AddProperty(buildPackageInfo.RunPropertyName, "true");
                runProperty.Condition = $" '$({buildPackageInfo.RunPropertyName})' == '' ";

                if (File.Exists(buildPackageInfo.PropsPath))
                {
                    ProjectImportElement import = propsProject.AddImport(buildPackageInfo.PropsPath);

                    import.Condition = $" '$({buildPackageInfo.EnablePropertyName})' == 'true' And '$({buildPackageInfo.RunPropertyName})' == 'true' ";
                }

                if (File.Exists(buildPackageInfo.TargetsPath))
                {
                    ProjectImportElement import = targetsProject.AddImport(buildPackageInfo.TargetsPath);

                    import.Condition = $" '$({buildPackageInfo.EnablePropertyName})' == 'true' And '$({buildPackageInfo.RunPropertyName})' == 'true' ";
                }

                Log.LogMessage($"  Generated imports for '{buildPackageInfo.Id}'.");
            }

            propsProject.Save();
            targetsProject.Save();
        }
Ejemplo n.º 23
0
        public override void Process(
            ProjectRootElement project,
            Dictionary <string, ProjectPropertyGroupElement> groups
            )
        {
            ProjectPropertyGroupElement globals;

            if (!groups.TryGetValue("Globals", out globals))
            {
                globals = project.AddPropertyGroup();
            }

            AddOrSetProperty(globals, "ProjectTypeGuids", "{c85cbf2e-4147-4e9d-87e0-9a2fbf407f6e};{888888A0-9F3D-457C-B088-3A5042F75D52}");
        }
Ejemplo n.º 24
0
 private bool AddBuildProperties(ProjectRootElement inMemoryProject, Microsoft.Build.Evaluation.Project originalProject)
 {
     foreach (ProjectPropertyGroupElement propertyGroup in originalProject.Xml.PropertyGroups)
     {
         ProjectPropertyGroupElement condition = inMemoryProject.AddPropertyGroup();
         condition.Condition = propertyGroup.Condition;
         foreach (ProjectPropertyElement property in propertyGroup.Properties)
         {
             ProjectPropertyElement projectPropertyElement = condition.AddProperty(property.Name, property.Value);
             projectPropertyElement.Condition = property.Condition;
         }
     }
     return(true);
 }
Ejemplo n.º 25
0
        public override void Process(
            ProjectRootElement project,
            Dictionary <string, ProjectPropertyGroupElement> groups
            )
        {
            ProjectPropertyGroupElement globals;

            if (!groups.TryGetValue("Globals", out globals))
            {
                globals = project.AddPropertyGroup();
            }

            AddOrSetProperty(globals, "ProjectTypeGuids", "{2b557614-1a2b-4903-b9df-ed20d7b63f3a};{888888A0-9F3D-457C-B088-3A5042F75D52}");
        }
Ejemplo n.º 26
0
        private void AddTargetFrameworkProperty()
        {
            var propGroup = _projectRootElement.PropertyGroups.FirstOrDefault(pg => pg.Condition == "");

            if (propGroup == null)
            {
                propGroup = _projectRootElement.AddPropertyGroup();
            }

            var targetFrameworkElement = _projectRootElement.CreatePropertyElement("TargetFramework");

            targetFrameworkElement.Value = _sdkBaselineProject.Project.FirstConfiguredProject.GetProperty("TargetFramework").EvaluatedValue;
            propGroup.PrependChild(targetFrameworkElement);
        }
Ejemplo n.º 27
0
        public void SetLabel()
        {
            ProjectRootElement project = ProjectRootElement.Create();

            project.AddPropertyGroup();
            Helpers.ClearDirtyFlag(project);

            ProjectPropertyGroupElement propertyGroup = Helpers.GetFirst(project.PropertyGroups);

            propertyGroup.Label = "c";

            Assert.Equal("c", propertyGroup.Label);
            Assert.True(project.HasUnsavedChanges);
        }
Ejemplo n.º 28
0
        public RepositoryProject(string repositoryRoot)
        {
            _doc = ProjectRootElement.Create(NewProjectFileOptions.None);
            var import    = _doc.CreateImportElement(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props");
            var propGroup = _doc.AddPropertyGroup();

            if (repositoryRoot[repositoryRoot.Length - 1] != '\\')
            {
                repositoryRoot += '\\';
            }
            propGroup.AddProperty("RepositoryRoot", repositoryRoot);
            _doc.AddItemGroup();
            _doc.PrependChild(import);
            _doc.AddImport(@"$(MSBuildToolsPath)\Microsoft.Common.targets");
        }
Ejemplo n.º 29
0
        internal void CreatePropsFile(IDictionary <string, string> propertyPairs, string propsFile)
        {
            ProjectRootElement project = ProjectRootElement.Create();

            ProjectPropertyGroupElement propertyGroup = project.AddPropertyGroup();

            propertyGroup.SetProperty("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)");

            foreach (var kvp in propertyPairs)
            {
                propertyGroup.SetProperty(kvp.Key, kvp.Value);
            }

            project.Save(propsFile);
        }
        private static void AddProperties(string projectName, ProjectRootElement root)
        {
            ProjectPropertyGroupElement group = root.AddPropertyGroup();

            group.AddProperty("Configuration", "Debug");
            group.AddProperty("Platform", "AnyCPU");
            group.AddProperty("ProjectGuid", Guid.NewGuid().ToString());
            group.AddProperty("OutputType", "Library");
            group.AddProperty("AppDesignerFolder", "Properties");
            group.AddProperty("RootNamespace", projectName);
            group.AddProperty("AssemblyName", projectName);
            group.AddProperty("TargetFrameworkVersion", "4.5.2");

            ProjectPropertyGroupElement conditionedGroup = root.AddPropertyGroup();

            conditionedGroup.AddProperty("DebugSymbols", "true");
            conditionedGroup.AddProperty("DebugType", "full");
            conditionedGroup.AddProperty("Optimize", "false");
            conditionedGroup.AddProperty("OutputPath", "bin\\Debug\\");
            conditionedGroup.AddProperty("DefineConstants", "DEBUG;TRACE");
            conditionedGroup.AddProperty("ErrorReport", "prompt");
            conditionedGroup.AddProperty("WarningLevel", "4");
            conditionedGroup.Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ";
        }