Exemple #1
0
        private void GenerateAndAddLegacyConfigurationPropertyGroup()
        {
            ProjectPropertyGroupElement group = Xml.AddPropertyGroup();

            group.AddProperty("ProjectGuidString", Guid.NewGuid().ToString("B").ToUpper());
            group.AddProperty("ProjectTypeGuids", VsProjectTypeGuids.LegacyProjectGuid);
        }
Exemple #2
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));
        }
Exemple #3
0
        private static void InitializeExtensibilityDebugParameters(ProjectRootElement root)
        {
            ProjectElement firstChild         = root.FirstChild;
            ProjectPropertyGroupElement group = root.CreatePropertyGroupElement();

            root.InsertAfterChild(group, firstChild);
            group.AddProperty("StartAction", "Program");
            group.AddProperty("StartProgram", "$(DevEnvDir)\\devenv.exe");
            group.AddProperty("StartArguments", "/RootSuffix Exp");
        }
Exemple #4
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);
        }
Exemple #5
0
        public static ProjectRootElement CreateLibraryProject(string name, string defaultConfig, out ProjectPropertyGroupElement mainGroup)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException($"{nameof(name)} cannot be empty", nameof(name));
            }

            var root = ProjectRootElement.Create();

            root.DefaultTargets = "Build";

            mainGroup = root.AddPropertyGroup();
            mainGroup.AddProperty("Configuration", defaultConfig).Condition = " '$(Configuration)' == '' ";
            mainGroup.AddProperty("Platform", "AnyCPU").Condition           = " '$(Platform)' == '' ";
            mainGroup.AddProperty("ProjectGuid", "{" + Guid.NewGuid().ToString().ToUpper() + "}");
            mainGroup.AddProperty("OutputType", "Library");
            mainGroup.AddProperty("OutputPath", Path.Combine("bin", "$(Configuration)"));
            mainGroup.AddProperty("RootNamespace", IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true));
            mainGroup.AddProperty("AssemblyName", name);
            mainGroup.AddProperty("TargetFrameworkVersion", "v4.7");
            mainGroup.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString());

            var exportDebugGroup = root.AddPropertyGroup();

            exportDebugGroup.Condition = " '$(Configuration)|$(Platform)' == 'ExportDebug|AnyCPU' ";
            exportDebugGroup.AddProperty("DebugSymbols", "true");
            exportDebugGroup.AddProperty("DebugType", "portable");
            exportDebugGroup.AddProperty("Optimize", "false");
            exportDebugGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;");
            exportDebugGroup.AddProperty("ErrorReport", "prompt");
            exportDebugGroup.AddProperty("WarningLevel", "4");
            exportDebugGroup.AddProperty("ConsolePause", "false");

            var exportReleaseGroup = root.AddPropertyGroup();

            exportReleaseGroup.Condition = " '$(Configuration)|$(Platform)' == 'ExportRelease|AnyCPU' ";
            exportReleaseGroup.AddProperty("DebugType", "portable");
            exportReleaseGroup.AddProperty("Optimize", "true");
            exportReleaseGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;");
            exportReleaseGroup.AddProperty("ErrorReport", "prompt");
            exportReleaseGroup.AddProperty("WarningLevel", "4");
            exportReleaseGroup.AddProperty("ConsolePause", "false");

            // References
            var referenceGroup = root.AddItemGroup();

            referenceGroup.AddItem("Reference", "System");
            var frameworkRefAssembliesItem = referenceGroup.AddItem("PackageReference", "Microsoft.NETFramework.ReferenceAssemblies");

            // Use metadata (child nodes) instead of attributes for the PackageReference.
            // This is for compatibility with 3.2, where GodotTools uses an old Microsoft.Build.
            frameworkRefAssembliesItem.AddMetadata("Version", "1.0.0");
            frameworkRefAssembliesItem.AddMetadata("PrivateAssets", "All");

            root.AddImport(Path.Combine("$(MSBuildBinPath)", "Microsoft.CSharp.targets").Replace("/", "\\"));

            return(root);
        }
        /// <summary>
        /// Populate the property group with the individual options
        /// </summary>
        private void PopulatePropertyGroup(ProjectPropertyGroupElement configPropertyGroup)
        {
            string propertyName;

            foreach (CompSwitchInfo compSwitchInfo in validCompilerSwitches)
            {
                propertyName = compSwitchInfo.SwitchProjectPropertyName;

                // No need to remove the already existing property node
                // since the switches we are dealing with couldnt have been
                // set anywhere else in the property pages except the additional
                // options

                switch (compSwitchInfo.SwitchValueType)
                {
                case SwitchValueType.SVT_Boolean:
                    if (null != compSwitchInfo.SwitchValue)
                    {
                        configPropertyGroup.AddProperty(
                            propertyName,
                            compSwitchInfo.SwitchValue.ToString().ToLower(CultureInfo.InvariantCulture)
                            );
                    }
                    break;

                case SwitchValueType.SVT_String:
                    if (null != compSwitchInfo.SwitchValue)
                    {
                        configPropertyGroup.AddProperty(
                            propertyName,
                            compSwitchInfo.SwitchValue.ToString()
                            );
                    }
                    break;

                case SwitchValueType.SVT_MultiString:
                    Debug.Assert(null != compSwitchInfo.SwitchValue, "Expected non null value for multistring switch");
                    if (0 != ((StringBuilder)(compSwitchInfo.SwitchValue)).Length)
                    {
                        configPropertyGroup.AddProperty(
                            propertyName,
                            compSwitchInfo.SwitchValue.ToString()
                            );
                    }
                    break;

                default:
                    Debug.Assert(false, "Unknown switch value type");
                    break;
                }
            }
        }
        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();
        }
Exemple #8
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);
        }
Exemple #9
0
        public Microsoft.Build.Evaluation.Project Orchestrate(string projConfFile)
        {
            Microsoft.Build.Evaluation.Project msbuildProj = ProjectCollection.GlobalProjectCollection.LoadProject(projConfFile);
            if (msbuildProj == null)
            {
                msbuildProj = new Microsoft.Build.Evaluation.Project(projConfFile);
                if (msbuildProj == null)
                {
                    return(null);
                }
            }
            ProjectRootElement projRoot = msbuildProj.Xml;

            if (projRoot == null)
            {
                return(null);
            }
            string instPath          = extensionServ.GetVSIXInstallPath();
            bool   need_save         = false;
            string cpTargetsFullPath = Path.GetDirectoryName(projConfFile) + "\\ChartPoints.targets";

            if (!File.Exists(cpTargetsFullPath))
            {
                bool res = CreateFileFromResource("ChartPointsLib.Resources.ChartPoints.targets", cpTargetsFullPath);
            }
            IEnumerable <ProjectImportElement> importElems = projRoot.Imports.Where(ig => (ig.Project == "ChartPoints.targets"));

            if (!importElems.Any())
            {
                projRoot.AddImport("ChartPoints.targets");
                need_save = true;
            }
            IEnumerable <ProjectPropertyGroupElement> cpPropsGroups = projRoot.PropertyGroups.Where(ig => (ig.Label == "CPTargetsVariables"));

            if (!cpPropsGroups.Any())
            {
                ProjectPropertyGroupElement cpPropsGroup = projRoot.AddPropertyGroup();
                cpPropsGroup.Label = "CPTargetsVariables";
                cpPropsGroup.AddProperty("TargetFileFullPath", instPath + "\\CPInstrBuildTask.dll");
                cpPropsGroup.AddProperty("ThisProjectFullName", "$(MSBuildThisFileFullPath)");
            }
            if (need_save)
            {
                msbuildProj.Save();
            }

            return(msbuildProj);
        }
Exemple #10
0
        /// <exception cref="ArgumentException">Value cannot be null or whitespace.</exception>
        /// <exception cref="InvalidProjectFileException">If the evaluation fails.</exception>
        public void Fix(
            [NotNull] Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            var needsNewPropertyGroup = true;

            /* First, remove all properties to replace with a configuration condition */
            foreach (ProjectPropertyGroupElement propertyGroupElement in
                     GetPropertyGroupsWithPropertyToReplace(project))
            {
                if (propertyGroupElement.Condition == string.Empty)
                {
                    /* This property group already defines the property for all configurations. We only need to set it
                     * to the requested value. */
                    needsNewPropertyGroup = false;
                    propertyGroupElement.SetProperty(_propertyName, _propertyValue);
                    continue;
                }

                ProjectPropertyElement property =
                    propertyGroupElement.Properties.Single(p => p.Name == _propertyName);
                propertyGroupElement.RemoveChild(property);
            }

            if (needsNewPropertyGroup)
            {
                /* Add PropertyGroup containing LangVersion for all build configurations */
                ProjectPropertyGroupElement newPropertyGroup = project.Xml.AddPropertyGroup();
                newPropertyGroup.AddProperty(_propertyName, _propertyValue);
            }
        }
Exemple #11
0
        private void SetPropertyUnderCondition(string propertyName, string propertyValue, string condition)
        {
            // New OM doesn't have a convenient equivalent for setting a property with a particular property group condition.
            // So do it ourselves.
            ProjectPropertyGroupElement newGroup = null;

            foreach (ProjectPropertyGroupElement group in this.proj.Xml.PropertyGroups)
            {
                if (String.Equals(group.Condition.Trim(), condition, StringComparison.OrdinalIgnoreCase))
                {
                    newGroup = group;
                    break;
                }
            }

            if (newGroup == null)
            {
                newGroup           = this.proj.Xml.AddPropertyGroup(); // Adds after last existing PG, else at start of project
                newGroup.Condition = condition;
            }

            foreach (ProjectPropertyElement property in newGroup.PropertiesReversed) // If there's dupes, pick the last one so we win
            {
                if (String.Equals(property.Name, propertyName, StringComparison.OrdinalIgnoreCase) && property.Condition.Length == 0)
                {
                    property.Value = propertyValue;
                    return;
                }
            }

            newGroup.AddProperty(propertyName, propertyValue);
        }
        public static void SetProperty(Microsoft.Build.Evaluation.Project project, String label, String name, String value)
        {
            ProjectPropertyGroupElement group = project.Xml.PropertyGroups.FirstOrDefault(g => g.Label.Equals(label));

            if (group == null)
            {
                //
                // Create our property group after the main language targets are imported so we can use the properties
                // defined in this files.
                //
                ProjectImportElement import = project.Xml.Imports.FirstOrDefault(
                    p => (p.Project.IndexOf("Microsoft.Cpp.targets") != -1 || p.Project.IndexOf("IceBuilder.CSharp.props") != -1));
                if (import != null)
                {
                    group = project.Xml.CreatePropertyGroupElement();
                    project.Xml.InsertAfterChild(group, import);
                }
                else
                {
                    group = project.Xml.CreatePropertyGroupElement();
                }
                group.Label = label;
            }

            ProjectPropertyElement property = group.Properties.FirstOrDefault(p => p.Name.Equals(name));

            if (property != null)
            {
                property.Value = value;
            }
            else
            {
                group.AddProperty(name, value);
            }
        }
Exemple #13
0
        public void WriteProjectInfo_AnalysisFileList_FilesTypes_SpecifiedPlusDefaults()
        {
            // Arrange
            string rootInputFolder  = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs");
            string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs");

            ProjectDescriptor  descriptor  = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "fileTypes.proj.txt");
            ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder);

            // Files we don't expect to be included by default
            string fooType1 = AddFileToProject(projectRoot, "fooType", sonarQubeExclude: null);
            string xxxType1 = AddFileToProject(projectRoot, "xxxType", sonarQubeExclude: null);

            AddFileToProject(projectRoot, "barType", sonarQubeExclude: null);

            // Files we'd normally expect to be included by default
            string managed1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, sonarQubeExclude: null);
            string content1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Content, sonarQubeExclude: null);

            // Update the "item types" property to add some extra item type
            // NB this has to be done *after* the integration targets have been imported
            ProjectPropertyGroupElement group = projectRoot.CreatePropertyGroupElement();

            projectRoot.AppendChild(group);
            group.AddProperty("SQAnalysisFileItemTypes", "fooType;$(SQAnalysisFileItemTypes);xxxType");
            projectRoot.Save();

            // Act
            ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder);

            // Assert
            AssertResultFileExists(projectInfo, AnalysisType.FilesToAnalyze, fooType1, xxxType1, content1, managed1);
        }
        /// <summary>
        /// Adds a property element to the current &lt;PropertyGroup /&gt;.  A property group is automatically added if necessary.  if <paramref name="unevaluatedValue"/> is <code>null</code>, the property is not added.
        /// </summary>
        /// <param name="propertyGroup">The <see cref="ProjectPropertyGroupElement"/> to add the property to.</param>
        /// <param name="name">The name of the property.</param>
        /// <param name="unevaluatedValue">The unevaluated value of the property.</param>
        /// <param name="condition">An optional condition to add to the property.</param>
        /// <param name="setIfEmpty">An optional value indicating whether or not a condition should be added that checks if the property has already been set.</param>
        /// <param name="label">An option label to add to the property.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        /// <remarks>
        /// The <paramref name="setIfEmpty"/> parameter will add a condition such as " '$(Property)' == '' " which will only set the property if it has not already been set.
        /// </remarks>
        private ProjectCreator Property(ProjectPropertyGroupElement propertyGroup, string name, string unevaluatedValue, string condition = null, bool setIfEmpty = false, string label = null)
        {
            if (unevaluatedValue == null)
            {
                return(this);
            }

            ProjectPropertyElement propertyElement = propertyGroup.AddProperty(name, unevaluatedValue);

            if (setIfEmpty && condition != null)
            {
                propertyElement.Condition = $" '$({propertyElement.Name})' == '' And {condition} ";
            }
            else if (setIfEmpty)
            {
                propertyElement.Condition = $" '$({propertyElement.Name})' == '' ";
            }
            else
            {
                propertyElement.Condition = condition;
            }

            if (label != null)
            {
                propertyElement.Label = label;
            }

            return(this);
        }
        /// <summary>
        /// Sets a property in the given project, overriding the existing value if it exists.
        /// </summary>
        /// <param name="project">The project in which the property will be set.</param>
        /// <param name="name">The name of the property.</param>
        /// <param name="value">The value of the property.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if <c>project</c>, <c>name</c>, or <c>value</c> is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown if <c>name</c> is empty or contains invalid characters.</exception>
        public void SetProperty(IVsProject project, string name, string value)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException(Resources.EmptyProperty, "name");
            }

            Project msbuildProject          = MSBuildProjectFromIVsProject(project);
            ProjectPropertyElement property = FindProperty(msbuildProject.Xml, name);

            if (property == null)
            {
                ProjectPropertyGroupElement group = msbuildProject.Xml.AddPropertyGroup();
                group.AddProperty(name, value);
            }
            else
            {
                property.Value = value;
            }
        }
Exemple #16
0
        protected virtual void CopyProperties(IProject sourceProject, IProject targetProject)
        {
            MSBuildBasedProject sp = sourceProject as MSBuildBasedProject;
            MSBuildBasedProject tp = targetProject as MSBuildBasedProject;

            if (sp != null && tp != null)
            {
                lock (sp.SyncRoot) {
                    lock (tp.SyncRoot) {
                        // Remove all PropertyGroups in target project:
                        foreach (ProjectPropertyGroupElement tpg in tp.MSBuildProjectFile.PropertyGroups)
                        {
                            tp.MSBuildProjectFile.RemoveChild(tpg);
                        }
                        // Copy all PropertyGroups from source project to target project:
                        foreach (ProjectPropertyGroupElement spg in sp.MSBuildProjectFile.PropertyGroups)
                        {
                            ProjectPropertyGroupElement tpg = tp.MSBuildProjectFile.AddPropertyGroup();
                            tpg.Condition = spg.Condition;
                            foreach (ProjectPropertyElement sprop in spg.Properties)
                            {
                                ProjectPropertyElement tprop = tpg.AddProperty(sprop.Name, sprop.Value);
                                tprop.Condition = sprop.Condition;
                            }
                        }

                        // use the newly created IdGuid instead of the copied one
                        tp.SetProperty(MSBuildBasedProject.ProjectGuidPropertyName, tp.IdGuid);
                    }
                }
            }
        }
Exemple #17
0
        public static ProjectRootElement CreateLibraryProject(string name, string defaultConfig, out ProjectPropertyGroupElement mainGroup)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException($"{nameof(name)} cannot be empty", nameof(name));
            }

            var root = ProjectRootElement.Create();

            root.DefaultTargets = "Build";

            mainGroup = root.AddPropertyGroup();
            mainGroup.AddProperty("Configuration", defaultConfig).Condition = " '$(Configuration)' == '' ";
            mainGroup.AddProperty("Platform", "AnyCPU").Condition           = " '$(Platform)' == '' ";
            mainGroup.AddProperty("ProjectGuid", "{" + Guid.NewGuid().ToString().ToUpper() + "}");
            mainGroup.AddProperty("OutputType", "Library");
            mainGroup.AddProperty("OutputPath", Path.Combine("bin", "$(Configuration)"));
            mainGroup.AddProperty("RootNamespace", IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true));
            mainGroup.AddProperty("AssemblyName", name);
            mainGroup.AddProperty("TargetFrameworkVersion", "v4.5");
            mainGroup.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString());

            var debugGroup = root.AddPropertyGroup();

            debugGroup.Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ";
            debugGroup.AddProperty("DebugSymbols", "true");
            debugGroup.AddProperty("DebugType", "portable");
            debugGroup.AddProperty("Optimize", "false");
            debugGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;");
            debugGroup.AddProperty("ErrorReport", "prompt");
            debugGroup.AddProperty("WarningLevel", "4");
            debugGroup.AddProperty("ConsolePause", "false");

            var releaseGroup = root.AddPropertyGroup();

            releaseGroup.Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ";
            releaseGroup.AddProperty("DebugType", "portable");
            releaseGroup.AddProperty("Optimize", "true");
            releaseGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;");
            releaseGroup.AddProperty("ErrorReport", "prompt");
            releaseGroup.AddProperty("WarningLevel", "4");
            releaseGroup.AddProperty("ConsolePause", "false");

            // References
            var referenceGroup = root.AddItemGroup();

            referenceGroup.AddItem("Reference", "System");

            root.AddImport(Path.Combine("$(MSBuildBinPath)", "Microsoft.CSharp.targets").Replace("/", "\\"));

            return(root);
        }
Exemple #18
0
        public void AddProperty_ExistingPropertySameName()
        {
            ProjectRootElement          project       = ProjectRootElement.Create();
            ProjectPropertyGroupElement propertyGroup = project.AddPropertyGroup();

            propertyGroup.AddProperty("p", "v1");
            propertyGroup.AddProperty("p", "v2");

            string expected = ObjectModelHelpers.CleanupFileContents(
                @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <PropertyGroup>
    <p>v1</p>
    <p>v2</p>
  </PropertyGroup>
</Project>");

            Helpers.VerifyAssertProjectContent(expected, project);
        }
        /// <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;
            }
        }
Exemple #20
0
        public static UniqueStringPropertyList FindOrCreatePropertyListByCondition(this ProjectPropertyGroupElement pgpe, string name, string condition)
        {
            var result = pgpe.Properties.FirstOrDefault(each => each.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) && each.Condition == condition);

            if (result == null)
            {
                result           = pgpe.AddProperty(name, "");
                result.Condition = condition;
            }
            return(new UniqueStringPropertyList(() => result.Value, (s) => result.Value = s));
        }
        private void AddOutputPath(ProjectPropertyGroupElement newConfig, string configName)
        {
            //add the output path
            string outputBasePath = this.ProjectMgr.OutputBaseRelativePath;

            if (outputBasePath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
            {
                outputBasePath = Path.GetDirectoryName(outputBasePath);
            }
            newConfig.AddProperty("OutputPath", Path.Combine(outputBasePath, configName) + Path.DirectorySeparatorChar.ToString());
        }
Exemple #22
0
        public override bool Execute()
        {
            bool result = true;

            string file = Path.Combine(m_stubsPath, m_name + ".featureproj");

            try
            {
                _EVAL.Project proj = new _EVAL.Project();

                Microsoft.Build.Evaluation.ProjectCollection projCol = proj.ProjectCollection;

                ProjectPropertyGroupElement bpg = proj.Xml.AddPropertyGroup();
                bpg.AddProperty("FeatureName", m_name);
                bpg.AddProperty("Guid", System.Guid.NewGuid().ToString("B"));
                bpg.AddProperty("Description", "<Add Feature Description Here>");
                bpg.AddProperty("Groups", "");
                bpg.AddProperty(m_name.ToUpper().Replace(".", "_") + "_FEATUREPROJ", "True");

                ProjectItemGroupElement big = proj.Xml.AddItemGroup();
                big.AddItem("InteropFeature", Path.GetFileNameWithoutExtension(m_assemblyName).Replace('.', '_'));
                big.AddItem("DriverLibs", Path.GetFileNameWithoutExtension(m_assemblyName).Replace('.', '_') + ".$(LIB_EXT)");
                big.AddItem("MMP_DAT_CreateDatabase", "$(BUILD_TREE_CLIENT)\\pe\\$(ENDIANNESS)\\" + m_assemblyName);
                big.AddItem("RequiredProjects", Path.Combine(m_stubsPath, m_nativeProjectFile));


                proj.Save(file);

                // after save, unload the project, so that if rebuilds it is able to regenerate the project file.
                ProjectRootElement pre = proj.Xml;
                projCol.UnloadProject(proj);
                projCol.UnloadProject(pre);
            }
            catch (Exception e)
            {
                Log.LogError("Error trying to create feature project file \"" + file + "\": " + e.Message);
                result = false;
            }

            return(result);
        }
        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);
        }
        /// <summary>
        /// Emulates the behavior of SetProperty(name, value, condition) on the old MSBuild object model.
        /// This finds a property group with the specified condition (or creates one if necessary) then sets the property in there.
        /// </summary>
        private void SetUserPropertyUnderCondition(string propertyName, string propertyValue, string condition)
        {
            string       conditionTrimmed          = (condition == null) ? String.Empty : condition.Trim();
            const string userProjectCreateProperty = "UserProject";

            if (Project.UserBuildProject == null)
            {
                Project.SetUserProjectProperty(userProjectCreateProperty, null);
            }

            if (conditionTrimmed.Length == 0)
            {
                var userProp = Project.UserBuildProject.GetProperty(userProjectCreateProperty);
                if (userProp != null)
                {
                    Project.UserBuildProject.RemoveProperty(userProp);
                }
                Project.UserBuildProject.SetProperty(propertyName, propertyValue);
                return;
            }

            // New OM doesn't have a convenient equivalent for setting a property with a particular property group condition.
            // So do it ourselves.
            ProjectPropertyGroupElement newGroup = null;

            foreach (ProjectPropertyGroupElement group in Project.UserBuildProject.Xml.PropertyGroups)
            {
                if (String.Equals(group.Condition.Trim(), conditionTrimmed, StringComparison.OrdinalIgnoreCase))
                {
                    newGroup = group;
                    break;
                }
            }

            if (newGroup == null)
            {
                newGroup           = Project.UserBuildProject.Xml.AddPropertyGroup(); // Adds after last existing PG, else at start of project
                newGroup.Condition = condition;
            }

            foreach (ProjectPropertyElement property in newGroup.PropertiesReversed) // If there's dupes, pick the last one so we win
            {
                if (string.Equals(property.Name, propertyName, StringComparison.OrdinalIgnoreCase) &&
                    (property.Condition == null || property.Condition.Length == 0))
                {
                    property.Value = propertyValue;
                    return;
                }
            }

            newGroup.AddProperty(propertyName, propertyValue);
        }
 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);
 }
Exemple #26
0
        private string AddScriptExtension(ProjectPropertyGroupElement propertyGroup, string scriptCommandline, string scriptId)
        {
            var scriptArguments = CommandGrammar.Process(
                scriptCommandline,
                (s) => null,
                preserveSurroundingQuotes: false);

            scriptArguments = scriptArguments.Where(argument => !string.IsNullOrEmpty(argument)).ToArray();
            var scriptCommand = scriptArguments.First();
            var propertyName  = $"MigratedScriptExtension_{scriptId}";

            var windowsScriptExtensionProperty = propertyGroup.AddProperty(propertyName,
                                                                           s_windowsScriptExtension);
            var unixScriptExtensionProperty = propertyGroup.AddProperty(propertyName,
                                                                        s_unixScriptExtension);

            windowsScriptExtensionProperty.Condition =
                $" '$(OS)' == 'Windows_NT' and Exists('{scriptCommand}{s_windowsScriptExtension}') ";
            unixScriptExtensionProperty.Condition =
                $" '$(OS)' != 'Windows_NT' and Exists('{scriptCommand}{s_unixScriptExtension}') ";

            return(propertyName);
        }
        private void PopulateEmptyConfig(ref ProjectPropertyGroupElement newConfig)
        {
            newConfig = this.project.BuildProject.Xml.AddPropertyGroup();
            foreach (KeyValuePair <KeyValuePair <string, string>, string> pair in this.NewConfigProperties)
            {
                var key = pair.Key;
                var unevaluatedValue = pair.Value;
                var element          = newConfig.AddProperty(key.Key, unevaluatedValue);

                if (!string.IsNullOrEmpty(key.Value))
                {
                    element.Condition = key.Value;
                }
            }
        }
        protected static void AddOrSetProperty(ProjectPropertyGroupElement group, string name, string value)
        {
            bool anySet = false;

            foreach (var prop in group.Properties.Where(p => p.Name == name))
            {
                prop.Value = value;
                anySet     = true;
            }

            if (!anySet)
            {
                group.AddProperty(name, value);
            }
        }
Exemple #29
0
        public void GetPropertyTest()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject();

            ProjectPropertyGroupElement group = project.Xml.AddPropertyGroup();

            group.AddProperty("foo", "bar");

            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            Assert.IsNull(accessor.GetProperty(vsProject, "blah"), "GetProperty did not return null with invalid name.");
            Assert.AreEqual("bar", accessor.GetProperty(vsProject, "foo"), "GetProperty did not return correct value.");
        }
        private void SetPropertyIfNotSet(Project project, ref ProjectPropertyGroupElement group, string name, string value, string condition = null)
        {
            string existingValue = project.GetPropertyValue(name);

            if (string.IsNullOrEmpty(existingValue))
            {
                group = group ?? project.Xml.AddPropertyGroup();
                var prop = group.AddProperty(name, value);
                if (condition != null)
                {
                    prop.Condition = condition;
                }
                project.MarkDirty();
            }
        }