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));
     }
 }
 public void AddElement(ProjectRootElement root)
 {
     var ret = root.AddPropertyGroup ();
     ret.Condition = Condition;
     foreach (var p in Properties) {
         var value = p.Value ();
         if (string.IsNullOrWhiteSpace (value))
             continue;
         var pe = ret.AddProperty (p.Name, value);
         pe.Condition = p.Condition;
     }
 }
示例#3
0
        public override void Process(
            ProjectRootElement project,
            Dictionary<string, ProjectPropertyGroupElement> groups
        ) {
            ProjectPropertyGroupElement imports;
            if (!groups.TryGetValue("Imports", out imports)) {
                imports = project.AddPropertyGroup();
            }

            AddOrSetProperty(imports, "PtvsTargetsFile", @"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets");
            project.AddImport("$(PtvsTargetsFile)").Condition = "Exists($(PtvsTargetsFile))";
            project.AddImport(@"$(MSBuildToolsPath)\Microsoft.Common.targets").Condition = "!Exists($(PtvsTargetsFile))";
        }
示例#4
0
 static ProjectPropertyGroupElement CreatePropertyGroup(ProjectRootElement root,
    string targetFrameworkVersion,
    string condition, string platform_condition,
    string configuration, string platform, bool unsafeMode,
    string assemblyName)
 {
     ProjectPropertyGroupElement group = root.AddPropertyGroup();
     var config = group.AddProperty("Configuration", configuration);
     config.Condition = condition;
     var platform_ = group.AddProperty("Platform", platform);
     platform_.Condition = platform_condition;
     group.AddProperty("SchemaVersion", "2.0");
     group.AddProperty("OutputType", "Library");
     group.AddProperty("TargetFrameworkVersion", targetFrameworkVersion);
     group.AddProperty("FileAlignment", "512");
     group.AddProperty("AssemblyName", assemblyName);
     return group;
 }
示例#5
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;
 }
		ProjectPropertyGroupElement AddNewPropertyGroup(ProjectRootElement targetProject, PropertyPosition position)
		{
			if (position == PropertyPosition.UseExistingOrCreateAfterLastImport) {
				var propertyGroup = targetProject.CreatePropertyGroupElement();
				targetProject.AppendChild(propertyGroup);
				return propertyGroup;
			}
			return targetProject.AddPropertyGroup();
		}
		/// <summary>
		/// copy properties from g into a new property group for newConfiguration and newPlatform
		/// </summary>
		void CopyProperties(ProjectRootElement project, ProjectPropertyGroupElement g, string newConfiguration, string newPlatform)
		{
			ProjectPropertyGroupElement ng = project.AddPropertyGroup();
			ng.Condition = CreateCondition(newConfiguration, newPlatform);
			foreach (var p in g.Properties) {
				ng.AddProperty(p.Name, p.Value).Condition = p.Condition;
			}
		}
示例#8
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", "{e614c764-6d9e-4607-9337-b7073809a0bd};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52}");
            AddOrSetProperty(globals, "LaunchProvider", PythonConstants.WebLauncherName);
            AddOrSetProperty(globals, "PythonDebugWebServerCommandArguments", "--debug $(CommandLineArguments)");
            AddOrSetProperty(globals, "PythonWsgiHandler", "{StartupModule}.wsgi_app()");

            project.AddImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Web.targets");
        }
示例#9
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}");
        }
示例#10
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", "{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52}");
            AddOrSetProperty(globals, "LaunchProvider", PythonConstants.WebLauncherName);

            project.AddImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Web.targets");
        }
示例#11
0
        public override void Process(
            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");

            project.AddImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Django.targets");
        }
示例#12
0
        protected override void UpgradeProject(
            ref ProjectRootElement projectXml,
            ref ProjectRootElement userProjectXml,
            Action<__VSUL_ERRORLEVEL, string> log
        ) {
            Version version;

            // ToolsVersion less than 4.0 (or unspecified) is not supported, so
            // set it to 4.0.
            if (!Version.TryParse(projectXml.ToolsVersion, out version) ||
                version < new Version(4, 0)) {
                projectXml.ToolsVersion = "4.0";
                log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, SR.GetString(SR.UpgradedToolsVersion));
            }

            // Importing a targets file from 2.1 Beta
            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, SR.GetString(SR.UpgradedBottleImports));
            }
            if (flaskImports.Any()) {
                var globals = projectXml.PropertyGroups.FirstOrDefault() ?? projectXml.AddPropertyGroup();
                AddOrSetProperty(globals, "PythonWsgiHandler", "{StartupModule}.wsgi_app");
                log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, SR.GetString(SR.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, SR.GetString(SR.UpgradedRemoveCommonProps));
            }
            
            if (projectXml.Imports.Count == 1 && projectXml.Imports.First().Project.Equals(CommonTargets, StringComparison.OrdinalIgnoreCase)) {
                projectXml.RemoveChild(projectXml.Imports.First());
                var group = projectXml.AddPropertyGroup();
                if (!projectXml.Properties.Any(p => p.Name == "VisualStudioVersion")) {
                    group.AddProperty("VisualStudioVersion", "10.0").Condition = "'$(VisualStudioVersion)' == ''";
                }
                group.AddProperty("PtvsTargetsFile", PtvsTargets);
                projectXml.AddImport("$(PtvsTargetsFile)").Condition = "Exists($(PtvsTargetsFile))";
                projectXml.AddImport(CommonTargets).Condition = "!Exists($(PtvsTargetsFile))";
                log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, SR.GetString(SR.UpgradedRemoveCommonTargets));
            }
        }
示例#13
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", "{789894c7-04a9-4a11-a6b5-3f4435165112};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52}");
            AddOrSetProperty(globals, "LaunchProvider", PythonConstants.WebLauncherName);
            AddOrSetProperty(globals, "WebBrowserUrl", "http://localhost");
            AddOrSetProperty(globals, "PythonWsgiHandler", "{StartupModule}.wsgi_app");

            project.AddImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Web.targets");
        }
		/// <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;
			}
		}
		void MSBuildSetProperty(ProjectRootElement targetProject, string propertyName, string newValue,
		                        string groupCondition, PropertyPosition position,
		                        bool treatPropertyValueAsLiteral)
		{
			if (treatPropertyValueAsLiteral)
				newValue = MSBuildInternals.Escape(newValue);
			if (groupCondition == null) {
				// MSBuild uses an empty string when there's no condition, so we need to do the same
				// for the comparison to succeed.
				groupCondition = string.Empty;
			}
			foreach (var propertyGroup in targetProject.PropertyGroups) {
				if (propertyGroup.Condition == groupCondition) {
					foreach (var property in propertyGroup.Properties.ToList()) {
						if (MSBuildInternals.PropertyNameComparer.Equals(property.Name, propertyName)) {
							property.Value = newValue;
							return;
						}
					}
				}
			}
			foreach (var propertyGroup in targetProject.PropertyGroups) {
				if (propertyGroup.Condition == groupCondition) {
					propertyGroup.AddProperty(propertyName, newValue);
					return;
				}
			}
			
			var newGroup = targetProject.AddPropertyGroup();
			newGroup.Condition = groupCondition;
			newGroup.AddProperty(propertyName, newValue);
		}
示例#16
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);
            }
        }