public virtual ProjectOptions GetProjectOptions(string config = null)
{
if (string.IsNullOrEmpty(config))
{
EnvDTE.Project automationObject = this.GetAutomationObject() as EnvDTE.Project;
try
{
config = Utilities.GetActiveConfigurationName(automationObject);
}
catch (InvalidOperationException)
{
// Can't figure out the active configuration. Perhaps during solution load, or in a unit test.
}
catch (COMException)
{
// We may be in solution load and don't have an active config yet.
}
}
if (this.options != null && String.Equals(this.options.Config, config, StringComparison.OrdinalIgnoreCase))
return this.options;
ProjectOptions options = CreateProjectOptions();
options.Config = config;
string targetFrameworkMoniker = GetProjectProperty("TargetFrameworkMoniker", false);
if (!string.IsNullOrEmpty(targetFrameworkMoniker))
{
try
{
options.TargetFrameworkMoniker = new FrameworkName(targetFrameworkMoniker);
}
catch (ArgumentException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
}
if (config == null)
{
this.options = options;
return options;
}
options.GenerateExecutable = true;
this.SetConfiguration(config);
string outputPath = this.GetOutputPath(this.currentConfig);
if (!String.IsNullOrEmpty(outputPath))
{
// 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(ProjectFileConstants.RootNamespace, false);
options.OutputAssembly = outputPath + this.GetAssemblyName(config);
string outputtype = GetProjectProperty(ProjectFileConstants.OutputType, false);
if (!string.IsNullOrEmpty(outputtype))
{
outputtype = outputtype.ToLower(CultureInfo.InvariantCulture);
}
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);
// 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), CultureInfo.InvariantCulture);
}
catch (ArgumentNullException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (ArgumentException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (FormatException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (OverflowException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
}
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 (!String.IsNullOrEmpty(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), CultureInfo.InvariantCulture);
}
catch (ArgumentNullException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (ArgumentException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (FormatException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (OverflowException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
}
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), CultureInfo.InvariantCulture);
}
catch (ArgumentNullException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (ArgumentException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (FormatException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (OverflowException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
}
this.options = options; // do this AFTER setting configuration so it doesn't clear it.
return options;
}