/// <include file='doc\Project.uex' path='docs/doc[@for="Project.GetAssemblyName"]/*' /> private string GetAssemblyName(MSBuild.PropertyGroup properties) { this.currentConfig = properties; string name = null; name = GetProjectProperty("AssemblyName"); if (name == null) name = this.Caption; string outputtype = GetProjectProperty("OutputType", false); if (outputtype == "library") { outputtype = outputtype.ToLower(); name += ".dll"; } else { name += ".exe"; } return name; }
/// <include file='doc\Project.uex' path='docs/doc[@for="Project.GetBoolAttr"]/*' /> private bool GetBoolAttr(MSBuild.PropertyGroup properties, string name) { this.currentConfig = properties; string s = GetProjectProperty(name); return (s != null && s.ToLower().Trim() == "true"); }
/// <include file='doc\Project.uex' path='docs/doc[@for="Project.GetProjectOptions"]/*' /> public virtual ProjectOptions GetProjectOptions(string config) { if (this.options != null) return this.options; ProjectOptions options = this.options = CreateProjectOptions(); if (config == null) return options; options.GenerateExecutable = true; // Set the active configuration this.projFile.GlobalProperties.SetProperty("Configuration", config); this.currentConfig = this.projFile.EvaluatedProperties; string outputPath = this.GetOutputPath(this.currentConfig); // absolutize relative to project folder location outputPath = Path.Combine(this.ProjectFolder, outputPath); // Set some default values options.OutputAssembly = outputPath + this.Caption + ".exe"; options.ModuleKind = ModuleKindFlags.ConsoleApplication; options.RootNamespace = GetProjectProperty("RootNamespace", false); options.OutputAssembly = outputPath + this.GetAssemblyName(config); string outputtype = GetProjectProperty("OutputType", false).ToLower(); if (outputtype == "library") { options.ModuleKind = ModuleKindFlags.DynamicallyLinkedLibrary; options.GenerateExecutable = false; // DLL's have no entry point. } else if (outputtype == "winexe") options.ModuleKind = ModuleKindFlags.WindowsApplication; else options.ModuleKind = ModuleKindFlags.ConsoleApplication; options.Win32Icon = GetProjectProperty("ApplicationIcon", false); options.MainClass = GetProjectProperty("StartupObject", false); string targetPlatform = GetProjectProperty("TargetPlatform", false); if (targetPlatform != null && targetPlatform.Length > 0) { try { options.TargetPlatform = (PlatformType)Enum.Parse(typeof(PlatformType), targetPlatform); } catch { } options.TargetPlatformLocation = GetProjectProperty("TargetPlatformLocation", false); this.SetTargetPlatform(options); } /* * other settings from CSharp we may want to adopt at some point... AssemblyKeyContainerName = "" //This is the key file used to sign the interop assembly generated when importing a com object via add reference AssemblyOriginatorKeyFile = "" DelaySign = "false" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" PreBuildEvent = "" PostBuildEvent = "" RunPostBuildEvent = "OnBuildSuccess" */ // transfer all config build options... if (GetBoolAttr(this.currentConfig, "AllowUnsafeBlocks")) { options.AllowUnsafeCode = true; } if (GetProjectProperty("BaseAddress", false) != null) { try { options.BaseAddress = Int64.Parse(GetProjectProperty("BaseAddress", false)); } catch { } } if (GetBoolAttr(this.currentConfig, "CheckForOverflowUnderflow")) { options.CheckedArithmetic = true; } if (GetProjectProperty("DefineConstants", false) != null) { options.DefinedPreProcessorSymbols = new StringCollection(); foreach (string s in GetProjectProperty("DefineConstants", false).Replace(" \t\r\n", "").Split(';')) { options.DefinedPreProcessorSymbols.Add(s); } } string docFile = GetProjectProperty("DocumentationFile", false); if (docFile != null && docFile != "") { options.XMLDocFileName = Path.Combine(this.ProjectFolder, docFile); } if (GetBoolAttr(this.currentConfig, "DebugSymbols")) { options.IncludeDebugInformation = true; } if (GetProjectProperty("FileAlignment", false) != null) { try { options.FileAlignment = Int32.Parse(GetProjectProperty("FileAlignment", false)); } catch { } } if (GetBoolAttr(this.currentConfig, "IncrementalBuild")) { options.IncrementalCompile = true; } if (GetBoolAttr(this.currentConfig, "Optimize")) { options.Optimize = true; } if (GetBoolAttr(this.currentConfig, "RegisterForComInterop")) { } if (GetBoolAttr(this.currentConfig, "RemoveIntegerChecks")) { } if (GetBoolAttr(this.currentConfig, "TreatWarningsAsErrors")) { options.TreatWarningsAsErrors = true; } if (GetProjectProperty("WarningLevel", false) != null) { try { options.WarningLevel = Int32.Parse(GetProjectProperty("WarningLevel", false)); } catch { } } foreach (MSBuild.Item reference in this.projFile.GetEvaluatedItemsByType("Reference")) { string file = reference.GetAttribute("AssemblyName") + ".dll"; string hint = reference.GetAttribute("HintPath"); if (hint != null && hint != "") { // probably relative to the current file... hint = hint.Replace(Path.DirectorySeparatorChar, '/'); Url url = new Url(this.BaseURI, hint); string path = url.AbsoluteUrl; file = path; } if (!options.ReferencedAssemblies.Contains(file)) options.ReferencedAssemblies.Add(file); } return options; }
private string GetOutputPath(MSBuild.PropertyGroup properties) { this.currentConfig = properties; string outputPath = GetProjectProperty("OutputPath"); if (outputPath != null && outputPath != "") { outputPath = outputPath.Replace('/', Path.DirectorySeparatorChar); if (outputPath[outputPath.Length - 1] != Path.DirectorySeparatorChar) outputPath += Path.DirectorySeparatorChar; } return outputPath; }
/// <include file='doc\Project.uex' path='docs/doc[@for="ImageNames.SetProjectProperty"]/*' /> public virtual void SetProjectProperty(string propertyName, string propertyValue) { if (propertyName == null) throw new ArgumentNullException("propertyName", "Cannot set a null project property"); if (propertyValue == null) { // if property already null, do nothing if (GetMsBuildProperty(propertyName, true) == null) return; // otherwise, set it to empty propertyValue = String.Empty; } this.projFile.SetProperty(propertyName, propertyValue, null); // property cache will need to be updated this.currentConfig = null; this.SetProjectFileDirty(true); return; }
private MSBuild.Property GetMsBuildProperty(string propertyName, bool resetCache) { if (resetCache || this.currentConfig == null) { // Get properties from project file and cache it // TODO: track the current active configuration and set that value before evaluating properties // in theory, this should only be called for global property. //this.ProjectMgr.projFile.GlobalProperties.SetProperty("Configuration", this.ConfigName); this.currentConfig = this.ProjectMgr.projFile.EvaluatedProperties; } if (this.currentConfig == null) throw new Exception("Failed to retrive properties"); // return property asked for return this.currentConfig[propertyName]; }