本文整理汇总了C#中CSharpCompilationOptions.WithOptimizationLevel方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilationOptions.WithOptimizationLevel方法的具体用法?C# CSharpCompilationOptions.WithOptimizationLevel怎么用?C# CSharpCompilationOptions.WithOptimizationLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpCompilationOptions
的用法示例。
在下文中一共展示了CSharpCompilationOptions.WithOptimizationLevel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
//.........这里部分代码省略.........
platform = Platform.AnyCpu32BitPreferred;
}
compilationOptions = compilationOptions.WithPlatform(platform);
}
}
if (options.AllowUnsafeBlocks.HasValue)
{
compilationOptions = compilationOptions.WithAllowUnsafe(options.AllowUnsafeBlocks.Value);
}
if (options.CheckForOverflowUnderflow.HasValue)
{
compilationOptions = compilationOptions.WithOverflowChecks(options.CheckForOverflowUnderflow.Value);
}
if (options.DelaySign != null)
{
bool delaySignExplicitlySet = options.DelaySign.Item1;
bool delaySign = options.DelaySign.Item2;
compilationOptions = compilationOptions.WithDelaySign(delaySignExplicitlySet ? delaySign : (bool?)null);
}
if (!string.IsNullOrEmpty(options.ApplicationConfiguration))
{
var appConfigPath = FileUtilities.ResolveRelativePath(options.ApplicationConfiguration, options.ProjectDirectory);
try
{
using (var appConfigStream = PortableShim.FileStream.Create(appConfigPath, PortableShim.FileMode.Open, PortableShim.FileAccess.Read))
{
compilationOptions = compilationOptions.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.LoadFromXml(appConfigStream));
}
}
catch (Exception)
{
}
}
if (!string.IsNullOrEmpty(options.KeyContainer))
{
compilationOptions = compilationOptions.WithCryptoKeyContainer(options.KeyContainer);
}
if (!string.IsNullOrEmpty(options.KeyFile))
{
var fullPath = FileUtilities.ResolveRelativePath(options.KeyFile, options.ProjectDirectory);
compilationOptions = compilationOptions.WithCryptoKeyFile(fullPath);
}
if (!string.IsNullOrEmpty(options.MainEntryPoint))
{
compilationOptions = compilationOptions.WithMainTypeName(options.MainEntryPoint);
}
if (!string.IsNullOrEmpty(options.ModuleAssemblyName))
{
compilationOptions = compilationOptions.WithModuleName(options.ModuleAssemblyName);
}
if (options.Optimize.HasValue)
{
compilationOptions = compilationOptions.WithOptimizationLevel(options.Optimize.Value ? OptimizationLevel.Release : OptimizationLevel.Debug);
}
if (!string.IsNullOrEmpty(options.Platform))
{
Platform plat;
if (Enum.TryParse<Platform>(options.Platform, ignoreCase: true, result: out plat))
{
compilationOptions = compilationOptions.WithPlatform(plat);
}
}
// Get options from the ruleset file, if any.
if (!string.IsNullOrEmpty(options.RuleSetFile))
{
var fullPath = FileUtilities.ResolveRelativePath(options.RuleSetFile, options.ProjectDirectory);
Dictionary<string, ReportDiagnostic> specificDiagnosticOptions;
var generalDiagnosticOption = RuleSet.GetDiagnosticOptionsFromRulesetFile(fullPath, out specificDiagnosticOptions);
compilationOptions = compilationOptions.WithGeneralDiagnosticOption(generalDiagnosticOption);
warnings.AddRange(specificDiagnosticOptions);
}
if (options.WarningsAsErrors.HasValue)
{
compilationOptions = compilationOptions.WithGeneralDiagnosticOption(options.WarningsAsErrors.Value ? ReportDiagnostic.Error : ReportDiagnostic.Default);
}
if (options.WarningLevel.HasValue)
{
compilationOptions = compilationOptions.WithWarningLevel(options.WarningLevel.Value);
}
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(warnings);
return new HostBuildData(
parseOptions,
compilationOptions);
}