提交 0f163c65 编写于 作者: J Jared Parsons

Merge pull request #2715 from jaredpar/workspaces

Remove code from Workspaces.VB/C#.Desktop
......@@ -11,7 +11,7 @@
namespace Microsoft.CodeAnalysis.Scripting
{
/// <summary>
/// Extends <see cref="MetadataFileReferenceResolver"/> to enable resolution of assembly
/// Extends MetadataFileReferenceResolver to enable resolution of assembly
/// simple names in the GAC.
/// </summary>
internal sealed class GacFileResolver : MetadataFileReferenceResolver
......
......@@ -21,6 +21,7 @@
<Reference Include="Microsoft.Build, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.Build.Framework, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.Build.Tasks.$(MSBuildAssemblyNameFragment), Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
<Reference Include="System.Collections.Immutable">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\System.Collections.Immutable.$(SystemCollectionsImmutableVersion)\lib\portable-net45+win8+wp8+wpa81\\System.Collections.Immutable.dll</HintPath>
......@@ -51,10 +52,6 @@
<Project>{1EE8CAD3-55F9-4D91-96B2-084641DA9A6C}</Project>
<Name>CodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj">
<Project>{B501A547-C911-4A05-AC6E-274A50DFF30E}</Project>
<Name>CSharpCodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\Core\Desktop\Workspaces.Desktop.csproj">
<Project>{2e87fa96-50bb-4607-8676-46521599f998}</Project>
<Name>Workspaces.Desktop</Name>
......@@ -63,16 +60,6 @@
<Project>{5F8D2414-064A-4B3A-9B42-8E2A04246BE5}</Project>
<Name>Workspaces</Name>
</ProjectReference>
<ProjectReference Include="..\Portable\CSharpWorkspace.csproj">
<Project>{21b239d0-d144-430f-a394-c066d58ee267}</Project>
<Name>CSharpWorkspace</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="LanguageServices\CSharpCommandLineArgumentsFactoryService.cs" />
<Compile Include="MSBuild\CSharpProjectFileLoader.cs" />
<Compile Include="MSBuild\CSharpProjectFileLoader.CSharpProjectFile.cs" />
<Compile Include="MSBuild\CSharpProjectFileLoaderFactory.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
......@@ -90,4 +77,4 @@
<Import Project="..\..\..\..\build\VSL.Imports.Closed.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -117,6 +117,7 @@
<Compile Include="CodeGeneration\UsingDirectivesAdder.cs" />
<Compile Include="CodeGeneration\UsingDirectivesAdder.Rewriter.cs" />
<Compile Include="Composition\CSharpWorkspaceFeatures.cs" />
<Compile Include="LanguageServices\CSharpHostBuildDataFactory.cs" />
<Compile Include="CSharpWorkspaceResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
......@@ -268,4 +269,4 @@
<Import Project="..\..\..\..\build\VSL.Imports.Closed.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
\ No newline at end of file
</Project>
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.CSharp.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp
{
[ExportLanguageService(typeof(ICommandLineArgumentsFactoryService), LanguageNames.CSharp), Shared]
internal sealed class CSharpCommandLineParserFactory : ICommandLineArgumentsFactoryService
{
public CommandLineArguments CreateCommandLineArguments(IEnumerable<string> arguments, string baseDirectory, bool isInteractive, string sdkDirectory)
{
var parser = isInteractive ? CSharpCommandLineParser.Interactive : CSharpCommandLineParser.Default;
return parser.Parse(arguments, baseDirectory, sdkDirectory);
}
}
[ExportLanguageService(typeof(IHostBuildDataFactory), LanguageNames.CSharp), Shared]
internal sealed class CSharpHostBuildDataFactory : IHostBuildDataFactory
{
public HostBuildData Create(HostBuildOptions options)
{
var parseOptions = new CSharpParseOptions(languageVersion: LanguageVersion.CSharp6, documentationMode: DocumentationMode.Parse);
var compilationOptions = new CSharpCompilationOptions(
OutputKind.ConsoleApplication,
xmlReferenceResolver: new XmlFileResolver(options.ProjectDirectory),
sourceReferenceResolver: new SourceFileResolver(ImmutableArray<string>.Empty, options.ProjectDirectory),
metadataReferenceResolver: new AssemblyReferenceResolver(
new MetadataFileReferenceResolver(ImmutableArray<string>.Empty, options.ProjectDirectory),
MetadataFileReferenceProvider.Default),
strongNameProvider: new DesktopStrongNameProvider(ImmutableArray.Create(options.ProjectDirectory, options.OutputDirectory)),
assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default);
var warnings = new List<KeyValuePair<string, ReportDiagnostic>>(options.Warnings);
if (options.OutputKind.HasValue)
{
var kind = options.OutputKind.Value;
compilationOptions = compilationOptions.WithOutputKind(kind);
if (compilationOptions.Platform == Platform.AnyCpu32BitPreferred &&
(kind == OutputKind.DynamicallyLinkedLibrary || kind == OutputKind.NetModule || kind == OutputKind.WindowsRuntimeMetadata))
{
compilationOptions = compilationOptions.WithPlatform(Platform.AnyCpu);
}
}
if (!string.IsNullOrEmpty(options.DefineConstants))
{
IEnumerable<Diagnostic> diagnostics;
parseOptions = parseOptions.WithPreprocessorSymbols(CSharpCommandLineParser.ParseConditionalCompilationSymbols(options.DefineConstants, out diagnostics));
}
if (options.DocumentationFile != null)
{
parseOptions = parseOptions.WithDocumentationMode(!string.IsNullOrEmpty(options.DocumentationFile) ? DocumentationMode.Diagnose : DocumentationMode.Parse);
}
if (options.LanguageVersion != null)
{
var languageVersion = CompilationOptionsConversion.GetLanguageVersion(options.LanguageVersion);
if (languageVersion.HasValue)
{
parseOptions = parseOptions.WithLanguageVersion(languageVersion.Value);
}
}
if (!string.IsNullOrEmpty(options.PlatformWith32BitPreference))
{
Platform platform;
if (Enum.TryParse<Platform>(options.PlatformWith32BitPreference, true, out platform))
{
if (platform == Platform.AnyCpu &&
compilationOptions.OutputKind != OutputKind.DynamicallyLinkedLibrary &&
compilationOptions.OutputKind != OutputKind.NetModule &&
compilationOptions.OutputKind != OutputKind.WindowsRuntimeMetadata)
{
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);
}
}
}
......@@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
......@@ -30,7 +31,7 @@ public static ProjectInfo CreateProjectInfo(string projectName, string language,
}
var commandLineArgumentsFactory = languageServices.GetRequiredService<ICommandLineArgumentsFactoryService>();
var commandLineArguments = commandLineArgumentsFactory.CreateCommandLineArguments(commandLineArgs, projectDirectory, isInteractive: false);
var commandLineArguments = commandLineArgumentsFactory.CreateCommandLineArguments(commandLineArgs, projectDirectory, isInteractive: false, sdkDirectory: RuntimeEnvironment.GetRuntimeDirectory());
// TODO (tomat): to match csc.exe/vbc.exe we should use CommonCommandLineCompiler.ExistingReferencesResolver to deal with #r's
var referenceResolver = new MetadataFileReferenceResolver(commandLineArguments.ReferencePaths, commandLineArguments.BaseDirectory);
......
......@@ -11,7 +11,6 @@
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Utilities;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.MSBuild;
......@@ -26,12 +25,16 @@ private class CSharpProjectFile : ProjectFile
{
private readonly IMetadataService _metadataService;
private readonly IAnalyzerService _analyzerService;
private readonly IHostBuildDataFactory _msbuildHost;
private readonly ICommandLineArgumentsFactoryService _commandLineArgumentsFactoryService;
public CSharpProjectFile(CSharpProjectFileLoader loader, MSB.Evaluation.Project project, IMetadataService metadataService, IAnalyzerService analyzerService)
: base(loader, project)
{
_metadataService = metadataService;
_analyzerService = analyzerService;
_msbuildHost = loader.MSBuildHost;
_commandLineArgumentsFactoryService = loader.CommandLineArgumentsFactoryService;
}
public override SourceCodeKind GetSourceCodeKind(string documentFileName)
......@@ -99,12 +102,13 @@ private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInput
var outputPath = Path.Combine(this.GetOutputDirectory(), compilerInputs.OutputFileName);
var assemblyName = this.GetAssemblyName();
var msbuildData = _msbuildHost.Create(compilerInputs.Options);
return new ProjectFileInfo(
outputPath,
assemblyName,
compilerInputs.CompilationOptions,
compilerInputs.ParseOptions,
msbuildData.CompilationOptions,
msbuildData.ParseOptions,
compilerInputs.CodePage,
docs,
additionalDocs,
......@@ -178,8 +182,7 @@ private ImmutableArray<string> GetAliases(MSB.Framework.ITaskItem item)
args.Add("/nostdlib");
}
var commandLineParser = CSharpCommandLineParser.Default;
var commandLineArgs = commandLineParser.Parse(args, executedProject.Directory, RuntimeEnvironment.GetRuntimeDirectory());
var commandLineArgs = _commandLineArgumentsFactoryService.CreateCommandLineArguments(args, executedProject.Directory, isInteractive: false, sdkDirectory: RuntimeEnvironment.GetRuntimeDirectory());
var resolver = new MetadataFileReferenceResolver(commandLineArgs.ReferencePaths, commandLineArgs.BaseDirectory);
metadataReferences = commandLineArgs.ResolveMetadataReferences(new AssemblyReferenceResolver(resolver, _metadataService.GetProvider()));
......@@ -271,8 +274,7 @@ private class CSharpCompilerInputs :
private readonly CSharpProjectFile _projectFile;
internal bool Initialized { get; private set; }
internal CSharpParseOptions ParseOptions { get; private set; }
internal CSharpCompilationOptions CompilationOptions { get; private set; }
internal HostBuildOptions Options { get; private set; }
internal int CodePage { get; private set; }
internal IEnumerable<MSB.Framework.ITaskItem> Sources { get; private set; }
internal IEnumerable<MSB.Framework.ITaskItem> References { get; private set; }
......@@ -280,33 +282,20 @@ private class CSharpCompilerInputs :
internal IEnumerable<MSB.Framework.ITaskItem> AdditionalFiles { get; private set; }
internal IReadOnlyList<string> LibPaths { get; private set; }
internal bool NoStandardLib { get; private set; }
internal Dictionary<string, ReportDiagnostic> Warnings { get; }
internal string OutputFileName { get; private set; }
private static readonly CSharpParseOptions s_defaultParseOptions = new CSharpParseOptions(languageVersion: LanguageVersion.CSharp6, documentationMode: DocumentationMode.Parse);
internal CSharpCompilerInputs(CSharpProjectFile projectFile)
{
_projectFile = projectFile;
var projectDirectory = Path.GetDirectoryName(projectFile.FilePath);
var outputDirectory = projectFile.GetOutputDirectory();
this.ParseOptions = s_defaultParseOptions;
this.CompilationOptions = new CSharpCompilationOptions(
OutputKind.ConsoleApplication,
xmlReferenceResolver: new XmlFileResolver(projectDirectory),
sourceReferenceResolver: new SourceFileResolver(ImmutableArray<string>.Empty, projectDirectory),
metadataReferenceResolver: new AssemblyReferenceResolver(
new MetadataFileReferenceResolver(ImmutableArray<string>.Empty, projectDirectory),
MetadataFileReferenceProvider.Default),
strongNameProvider: new DesktopStrongNameProvider(ImmutableArray.Create(projectDirectory, outputDirectory)),
assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default);
this.Warnings = new Dictionary<string, ReportDiagnostic>();
this.Options = new HostBuildOptions();
this.Sources = SpecializedCollections.EmptyEnumerable<MSB.Framework.ITaskItem>();
this.References = SpecializedCollections.EmptyEnumerable<MSB.Framework.ITaskItem>();
this.AnalyzerReferences = SpecializedCollections.EmptyEnumerable<MSB.Framework.ITaskItem>();
this.AdditionalFiles = SpecializedCollections.EmptyEnumerable<MSB.Framework.ITaskItem>();
this.LibPaths = SpecializedCollections.EmptyReadOnlyList<string>();
this.Options.ProjectDirectory = Path.GetDirectoryName(projectFile.FilePath);
this.Options.OutputDirectory = projectFile.GetOutputDirectory();
}
public bool Compile()
......@@ -320,11 +309,6 @@ public void BeginInitialization()
public bool EndInitialization(out string errorMessage, out int errorCode)
{
if (this.Warnings.Count > 0)
{
this.CompilationOptions = this.CompilationOptions.WithSpecificDiagnosticOptions(this.Warnings);
}
this.Initialized = true;
errorMessage = string.Empty;
errorCode = 0;
......@@ -339,25 +323,8 @@ public bool SetHighEntropyVA(bool highEntropyVA)
public bool SetPlatformWith32BitPreference(string platformWith32BitPreference)
{
if (!string.IsNullOrEmpty(platformWith32BitPreference))
{
Platform platform;
if (Enum.TryParse<Platform>(platformWith32BitPreference, true, out platform))
{
if (platform == Platform.AnyCpu &&
this.CompilationOptions.OutputKind != OutputKind.DynamicallyLinkedLibrary &&
this.CompilationOptions.OutputKind != OutputKind.NetModule &&
this.CompilationOptions.OutputKind != OutputKind.WindowsRuntimeMetadata)
{
platform = Platform.AnyCpu32BitPreferred;
}
this.CompilationOptions = this.CompilationOptions.WithPlatform(platform);
return true;
}
}
return false;
this.Options.PlatformWith32BitPreference = platformWith32BitPreference;
return true;
}
public bool SetSubsystemVersion(string subsystemVersion)
......@@ -368,21 +335,7 @@ public bool SetSubsystemVersion(string subsystemVersion)
public bool SetApplicationConfiguration(string applicationConfiguration)
{
if (!string.IsNullOrEmpty(applicationConfiguration))
{
var appConfigPath = FileUtilities.ResolveRelativePath(applicationConfiguration, Path.GetDirectoryName(_projectFile.FilePath));
try
{
using (var appConfigStream = new FileStream(appConfigPath, FileMode.Open, FileAccess.Read))
{
this.CompilationOptions = this.CompilationOptions.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.LoadFromXml(appConfigStream));
}
}
catch (Exception)
{
}
}
this.Options.ApplicationConfiguration = applicationConfiguration;
return true;
}
......@@ -416,7 +369,7 @@ public bool SetAdditionalLibPaths(string[] additionalLibPaths)
public bool SetAllowUnsafeBlocks(bool allowUnsafeBlocks)
{
this.CompilationOptions = this.CompilationOptions.WithAllowUnsafe(allowUnsafeBlocks);
this.Options.AllowUnsafeBlocks = allowUnsafeBlocks;
return true;
}
......@@ -428,7 +381,7 @@ public bool SetBaseAddress(string baseAddress)
public bool SetCheckForOverflowUnderflow(bool checkForOverflowUnderflow)
{
this.CompilationOptions = this.CompilationOptions.WithOverflowChecks(checkForOverflowUnderflow);
this.Options.CheckForOverflowUnderflow = checkForOverflowUnderflow;
return true;
}
......@@ -448,21 +401,15 @@ public bool SetDebugType(string debugType)
public bool SetDefineConstants(string defineConstants)
{
if (!string.IsNullOrEmpty(defineConstants))
{
IEnumerable<Diagnostic> diagnostics;
this.ParseOptions = this.ParseOptions.WithPreprocessorSymbols(CSharpCommandLineParser.ParseConditionalCompilationSymbols(defineConstants, out diagnostics));
return true;
}
return false;
this.Options.DefineConstants = defineConstants;
return true;
}
private static readonly char[] s_preprocessorSymbolSeparators = new char[] { ';', ',' };
public bool SetDelaySign(bool delaySignExplicitlySet, bool delaySign)
{
this.CompilationOptions = this.CompilationOptions.WithDelaySign(delaySignExplicitlySet ? delaySign : (bool?)null);
this.Options.DelaySign = Tuple.Create(delaySignExplicitlySet, delaySign);
return true;
}
......@@ -481,11 +428,11 @@ private void SetWarnings(string warnings, ReportDiagnostic reportStyle)
int warningId;
if (int.TryParse(warning, out warningId))
{
this.Warnings["CS" + warningId.ToString("0000")] = reportStyle;
this.Options.Warnings["CS" + warningId.ToString("0000")] = reportStyle;
}
else
{
this.Warnings[warning] = reportStyle;
this.Options.Warnings[warning] = reportStyle;
}
}
}
......@@ -493,8 +440,7 @@ private void SetWarnings(string warnings, ReportDiagnostic reportStyle)
public bool SetDocumentationFile(string documentationFile)
{
this.ParseOptions = this.ParseOptions.WithDocumentationMode(!string.IsNullOrEmpty(documentationFile) ? DocumentationMode.Diagnose : DocumentationMode.Parse);
this.Options.DocumentationFile = documentationFile;
return true;
}
......@@ -524,33 +470,19 @@ public bool SetGenerateFullPaths(bool generateFullPaths)
public bool SetKeyContainer(string keyContainer)
{
if (!string.IsNullOrEmpty(keyContainer))
{
this.CompilationOptions = this.CompilationOptions.WithCryptoKeyContainer(keyContainer);
}
this.Options.KeyContainer = keyContainer;
return true;
}
public bool SetKeyFile(string keyFile)
{
if (!string.IsNullOrEmpty(keyFile))
{
var fullPath = FileUtilities.ResolveRelativePath(keyFile, Path.GetDirectoryName(_projectFile.FilePath));
this.CompilationOptions = this.CompilationOptions.WithCryptoKeyFile(fullPath);
}
this.Options.KeyFile = keyFile;
return true;
}
public bool SetLangVersion(string langVersion)
{
var languageVersion = CompilationOptionsConversion.GetLanguageVersion(langVersion);
if (languageVersion.HasValue)
{
this.ParseOptions = this.ParseOptions.WithLanguageVersion(languageVersion.Value);
}
this.Options.LanguageVersion = langVersion;
return true;
}
......@@ -562,22 +494,13 @@ public bool SetLinkResources(MSB.Framework.ITaskItem[] linkResources)
public bool SetMainEntryPoint(string targetType, string mainEntryPoint)
{
// TODO: targetType is redundant? Already has SetTargetType()?
if (!string.IsNullOrEmpty(mainEntryPoint))
{
this.CompilationOptions = this.CompilationOptions.WithMainTypeName(mainEntryPoint);
}
this.Options.MainEntryPoint = mainEntryPoint;
return true;
}
public bool SetModuleAssemblyName(string moduleAssemblyName)
{
if (!string.IsNullOrEmpty(moduleAssemblyName))
{
this.CompilationOptions = this.CompilationOptions.WithModuleName(moduleAssemblyName);
}
this.Options.ModuleAssemblyName = moduleAssemblyName;
return true;
}
......@@ -595,7 +518,7 @@ public bool SetNoStandardLib(bool noStandardLib)
public bool SetOptimize(bool optimize)
{
this.CompilationOptions = this.CompilationOptions.WithOptimizationLevel(optimize ? OptimizationLevel.Release : OptimizationLevel.Debug);
this.Options.Optimize = optimize;
return true;
}
......@@ -614,17 +537,8 @@ public bool SetPdbFile(string pdbFile)
public bool SetPlatform(string platform)
{
if (!string.IsNullOrEmpty(platform))
{
Platform plat;
if (Enum.TryParse<Platform>(platform, ignoreCase: true, result: out plat))
{
this.CompilationOptions = this.CompilationOptions.WithPlatform(plat);
return true;
}
}
return false;
this.Options.Platform = platform;
return true;
}
public bool SetReferences(MSB.Framework.ITaskItem[] references)
......@@ -666,46 +580,29 @@ public bool SetSources(MSB.Framework.ITaskItem[] sources)
public bool SetTargetType(string targetType)
{
OutputKind kind;
if (!string.IsNullOrEmpty(targetType) && ProjectFile.TryGetOutputKind(targetType, out kind))
if (ProjectFile.TryGetOutputKind(targetType, out kind))
{
this.CompilationOptions = this.CompilationOptions.WithOutputKind(kind);
if (this.CompilationOptions.Platform == Platform.AnyCpu32BitPreferred &&
(kind == OutputKind.DynamicallyLinkedLibrary || kind == OutputKind.NetModule || kind == OutputKind.WindowsRuntimeMetadata))
{
this.CompilationOptions = this.CompilationOptions.WithPlatform(Platform.AnyCpu);
}
return true;
this.Options.OutputKind = kind;
}
return false;
return true;
}
public bool SetRuleSet(string ruleSetFile)
{
// Get options from the ruleset file, if any.
if (!string.IsNullOrEmpty(ruleSetFile))
{
var fullPath = FileUtilities.ResolveRelativePath(ruleSetFile, Path.GetDirectoryName(_projectFile.FilePath));
Dictionary<string, ReportDiagnostic> specificDiagnosticOptions;
var generalDiagnosticOption = RuleSet.GetDiagnosticOptionsFromRulesetFile(fullPath, out specificDiagnosticOptions);
this.CompilationOptions = this.CompilationOptions.WithGeneralDiagnosticOption(generalDiagnosticOption);
this.Warnings.AddRange(specificDiagnosticOptions);
}
this.Options.RuleSetFile = ruleSetFile;
return true;
}
public bool SetTreatWarningsAsErrors(bool treatWarningsAsErrors)
{
this.CompilationOptions = this.CompilationOptions.WithGeneralDiagnosticOption(treatWarningsAsErrors ? ReportDiagnostic.Error : ReportDiagnostic.Default);
this.Options.WarningsAsErrors = treatWarningsAsErrors;
return true;
}
public bool SetWarningLevel(int warningLevel)
{
this.CompilationOptions = this.CompilationOptions.WithWarningLevel(warningLevel);
this.Options.WarningLevel = warningLevel;
return true;
}
......
......@@ -23,6 +23,16 @@ public override string Language
get { return LanguageNames.CSharp; }
}
public IHostBuildDataFactory MSBuildHost
{
get { return _workspaceServices.GetLanguageServices(Language).GetService<IHostBuildDataFactory>(); }
}
public ICommandLineArgumentsFactoryService CommandLineArgumentsFactoryService
{
get { return _workspaceServices.GetLanguageServices(Language).GetService<ICommandLineArgumentsFactoryService>(); }
}
protected override ProjectFile CreateProjectFile(MSB.Evaluation.Project loadedProject)
{
return new CSharpProjectFile(this, loadedProject, _workspaceServices.GetService<IMetadataService>(), _workspaceServices.GetService<IAnalyzerService>());
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Composition;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.MSBuild;
namespace Microsoft.CodeAnalysis.CSharp
namespace Microsoft.CodeAnalysis.VisualBasic
{
[ExportLanguageService(typeof(ICommandLineArgumentsFactoryService), LanguageNames.CSharp), Shared]
internal class CSharpCommandLineArgumentsFactoryService : ICommandLineArgumentsFactoryService
[ExportLanguageServiceFactory(typeof(IProjectFileLoader), LanguageNames.VisualBasic), Shared()]
[ProjectFileExtension("vbproj")]
[ProjectTypeGuid("F184B08F-C81C-45F6-A57F-5ABD9991F28F")]
internal class VisualBasicProjectFileLoaderFactory : ILanguageServiceFactory
{
public CommandLineArguments CreateCommandLineArguments(IEnumerable<string> arguments, string baseDirectory, bool isInteractive)
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
{
var parser = isInteractive ? CSharpCommandLineParser.Interactive : CSharpCommandLineParser.Default;
return parser.Parse(arguments, baseDirectory, RuntimeEnvironment.GetRuntimeDirectory());
return new VisualBasicProjectFileLoader(languageServices.WorkspaceServices);
}
}
}
}
\ No newline at end of file
......@@ -55,34 +55,17 @@
<ItemGroup>
<Reference Include="Microsoft.Build, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.Build.Framework, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.Build.Tasks.$(MSBuildAssemblyNameFragment), Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Compilers\Core\Portable\AssemblyReferenceResolver.cs">
<Link>InternalUtilities\AssemblyReferenceResolver.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\MetadataFileReferenceResolver.cs">
<Link>InternalUtilities\MetadataFileReferenceResolver.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\EncodedStringText.cs">
<Link>InternalUtilities\EncodedStringText.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\FileKey.cs">
<Link>InternalUtilities\FileKey.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\ReflectionUtil.cs">
<Link>InternalUtilities\ReflectionUtil.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\PortableShim.cs">
<Link>InternalUtilities\PortableShim.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\FileSystem\FileUtilities.cs">
<Link>InternalUtilities\FileUtilities.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\FileSystem\PathUtilities.cs">
<Link>InternalUtilities\PathUtilities.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Helpers\AbstractAnalyzerAssemblyLoader.cs">
<Link>InternalUtilities\AbstractAnalyzerAssemblyLoader.cs</Link>
</Compile>
......@@ -115,7 +98,6 @@
</Compile>
<Compile Include="Workspace\CommandLineProject.cs" />
<Compile Include="Workspace\FileTextLoader.cs" />
<Compile Include="Workspace\Host\CommandLineArgumentsFactory\ICommandLineArgumentsFactoryService.cs" />
<Compile Include="Workspace\Host\Documentation\DocumentationProviderServiceFactory.cs" />
<Compile Include="Workspace\Host\Mef\DesktopMefHostServices.cs" />
<Compile Include="Workspace\Host\Mef\MefV1HostServices.cs" />
......@@ -123,6 +105,9 @@
<Compile Include="Workspace\Host\TemporaryStorage\TemporaryStorageServiceFactory.cs" />
<Compile Include="Workspace\Host\TemporaryStorage\TemporaryStorageServiceFactory.MemoryMappedFiles.cs" />
<Compile Include="Workspace\Host\TextFactory\DesktopTextFactoryService.cs" />
<Compile Include="Workspace\MSBuild\CSharp\CSharpProjectFileLoader.cs" />
<Compile Include="Workspace\MSBuild\CSharp\CSharpProjectFileLoader.CSharpProjectFile.cs" />
<Compile Include="Workspace\MSBuild\CSharp\CSharpProjectFileLoaderFactory.cs" />
<Compile Include="Workspace\MSBuild\MSBuildWorkspace.cs" />
<Compile Include="Workspace\MSBuild\ProjectFile\BuildTargets.cs" />
<Compile Include="Workspace\MSBuild\ProjectFile\DocumentFileInfo.cs" />
......@@ -138,6 +123,8 @@
<Compile Include="Workspace\MSBuild\SolutionFile\ProjectBlock.cs" />
<Compile Include="Workspace\MSBuild\SolutionFile\SectionBlock.cs" />
<Compile Include="Workspace\MSBuild\SolutionFile\SolutionFile.cs" />
<Compile Include="Workspace\MSBuild\VisualBasic\VisualBasicProjectFileLoader.cs" />
<Compile Include="Workspace\MSBuild\VisualBasic\VisualBasicProjectFileLoaderFactory.cs" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop" />
......@@ -189,4 +176,4 @@
<Import Project="..\..\..\..\build\VSL.Imports.Closed.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis
{
internal sealed class HostBuildOptions
{
public string ProjectDirectory { get; set; }
public string OutputDirectory { get; set; }
public string DefineConstants { get; set; }
public string DocumentationFile { get; set; }
public string LanguageVersion { get; set; }
public string PlatformWith32BitPreference { get; set; }
public string ApplicationConfiguration { get; set; }
public string KeyContainer { get; set; }
public string KeyFile { get; set; }
public string MainEntryPoint { get; set; }
public string ModuleAssemblyName { get; set; }
public string Platform { get; set; }
public string RuleSetFile { get; set; }
public string OptionCompare { get; set; }
public string OptionStrict { get; set; }
public string RootNamespace { get; set; }
public string VBRuntime { get; set; }
public bool? AllowUnsafeBlocks { get; set; }
public bool? CheckForOverflowUnderflow { get; set; }
public bool? Optimize { get; set; }
public bool? WarningsAsErrors { get; set; }
public bool? NoWarnings { get; set; }
public bool? OptionExplicit { get; set; }
public bool? OptionInfer { get; set; }
public int? WarningLevel { get; set; }
public OutputKind? OutputKind { get; set; }
public Tuple<bool, bool> DelaySign { get; set; }
public List<string> GlobalImports { get; set; }
public Dictionary<string, ReportDiagnostic> Warnings { get; set; }
internal HostBuildOptions()
{
Warnings = new Dictionary<string, ReportDiagnostic>();
GlobalImports = new List<string>();
}
}
internal sealed class HostBuildData
{
internal readonly ParseOptions ParseOptions;
internal readonly CompilationOptions CompilationOptions;
internal HostBuildData(ParseOptions parseOptions, CompilationOptions compilationOptions)
{
ParseOptions = parseOptions;
CompilationOptions = compilationOptions;
}
}
internal interface IHostBuildDataFactory : ILanguageService
{
HostBuildData Create(HostBuildOptions options);
}
}
......@@ -6,6 +6,6 @@ namespace Microsoft.CodeAnalysis.Host
{
internal interface ICommandLineArgumentsFactoryService : ILanguageService
{
CommandLineArguments CreateCommandLineArguments(IEnumerable<string> arguments, string baseDirectory, bool isInteractive);
CommandLineArguments CreateCommandLineArguments(IEnumerable<string> arguments, string baseDirectory, bool isInteractive, string sdkDirectory);
}
}
......@@ -226,6 +226,24 @@
<Compile Include="..\..\..\Compilers\Core\Portable\Serialization\SimpleRecordingObjectBinder.cs">
<Link>Serialization\SimpleRecordingObjectBinder.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\FileSystem\FileUtilities.cs">
<Link>InternalUtilities\FileUtilities.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\FileSystem\PathUtilities.cs">
<Link>InternalUtilities\PathUtilities.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\AssemblyReferenceResolver.cs">
<Link>InternalUtilities\AssemblyReferenceResolver.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\MetadataFileReferenceResolver.cs">
<Link>InternalUtilities\MetadataFileReferenceResolver.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\ReflectionUtil.cs">
<Link>InternalUtilities\ReflectionUtil.cs</Link>
</Compile>
<Compile Include="..\..\..\Compilers\Core\Portable\PortableShim.cs">
<Link>InternalUtilities\PortableShim.cs</Link>
</Compile>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
......@@ -384,6 +402,7 @@
<Compile Include="Log\Logger.LogBlock.cs" />
<Compile Include="Log\LogMessage.cs" />
<Compile Include="Log\WorkspaceErrorLogger.cs" />
<Compile Include="HostBuild.cs" />
<Compile Include="Rename\TokenRenameInfo.cs" />
<Compile Include="Serialization\AssemblySerializationInfoService.cs" />
<Compile Include="Serialization\IAssemblySerializationInfoService.cs" />
......@@ -548,6 +567,7 @@
<Compile Include="Utilities\ImmutableArrayExtensions.cs" />
<Compile Include="Utilities\ObjectPools\PooledObject.cs" />
<Compile Include="Workspace\Host\Caching\IWorkspaceCacheService.cs" />
<Compile Include="Workspace\Host\CommandLineArgumentsFactory\ICommandLineArgumentsFactoryService.cs" />
<Compile Include="Workspace\Host\Mef\ILanguagesMetadata.cs" />
<Compile Include="Workspace\Host\Mef\CodeChangeProviderMetadata.cs" />
<Compile Include="Workspace\Host\Mef\IMefHostExportProvider.cs" />
......
......@@ -52,10 +52,6 @@
<Project>{1EE8CAD3-55F9-4D91-96B2-084641DA9A6C}</Project>
<Name>CodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Compilers\VisualBasic\Portable\BasicCodeAnalysis.vbproj">
<Project>{2523D0E6-DF32-4A3E-8AE0-A19BFFAE2EF6}</Project>
<Name>BasicCodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\Core\Desktop\Workspaces.Desktop.csproj">
<Project>{2e87fa96-50bb-4607-8676-46521599f998}</Project>
<Name>Workspaces.Desktop</Name>
......@@ -72,11 +68,6 @@
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<ItemGroup>
<Compile Include="LanguageServices\VisualBasicCommandLineArgumentsFactoryService.vb" />
<Compile Include="MSBuild\VisualBasicProjectFileLoader.vb" />
<Compile Include="MSBuild\VisualBasicProjectFileLoaderFactory.vb" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
......@@ -88,4 +79,4 @@
<Import Project="..\..\..\..\build\VSL.Imports.Closed.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports System.Runtime.InteropServices
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.LanguageServices
Namespace Microsoft.CodeAnalysis.VisualBasic
<ExportLanguageService(GetType(ICommandLineArgumentsFactoryService), LanguageNames.VisualBasic), [Shared]>
Friend Class VisualBasicCommandLineArgumentsFactoryService
Implements ICommandLineArgumentsFactoryService
Public Function CreateCommandLineArguments(arguments As IEnumerable(Of String), baseDirectory As String, isInteractive As Boolean) As CommandLineArguments Implements ICommandLineArgumentsFactoryService.CreateCommandLineArguments
Dim parser = If(isInteractive, VisualBasicCommandLineParser.Interactive, VisualBasicCommandLineParser.Default)
Return parser.Parse(arguments, baseDirectory, RuntimeEnvironment.GetRuntimeDirectory())
End Function
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.MSBuild
Namespace Microsoft.CodeAnalysis.VisualBasic
<ExportLanguageServiceFactory(GetType(IProjectFileLoader), LanguageNames.VisualBasic), [Shared]>
<ProjectFileExtension("vbproj")>
<ProjectTypeGuid("F184B08F-C81C-45F6-A57F-5ABD9991F28F")>
Friend Class VisualBasicProjectFileLoaderFactory
Implements ILanguageServiceFactory
Public Function CreateLanguageService(languageServices As HostLanguageServices) As ILanguageService Implements ILanguageServiceFactory.CreateLanguageService
Return New VisualBasicProjectFileLoader(languageServices.WorkspaceServices)
End Function
End Class
End Namespace
......@@ -203,6 +203,7 @@
<Compile Include="Formatting\Rules\StructuredTriviaFormattingRule.vb" />
<Compile Include="Formatting\VisualBasicSyntaxFormattingService.vb" />
<Compile Include="LanguageServices\VisualBasicCompilationFactoryService.vb" />
<Compile Include="LanguageServices\VisualBasicHostBuildDataFactory.vb" />
<Compile Include="LanguageServices\VisualBasicSemanticFactsService.vb" />
<Compile Include="LanguageServices\VisualBasicSymbolDeclarationService.vb" />
<Compile Include="LanguageServices\VisualBasicSyntaxFactsService.vb" />
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Composition
Imports System.Linq
Imports System.Runtime.InteropServices
Imports System.Threading
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.LanguageServices
Imports Microsoft.CodeAnalysis.VisualBasic.Extensions.ContextQuery
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Roslyn.Utilities
Namespace Microsoft.CodeAnalysis.VisualBasic
<ExportLanguageService(GetType(ICommandLineArgumentsFactoryService), LanguageNames.VisualBasic), [Shared]>
Friend Class VisualBasicCommandLineArgumentsFactoryService
Implements ICommandLineArgumentsFactoryService
Public Function CreateCommandLineArguments(arguments As IEnumerable(Of String), baseDirectory As String, isInteractive As Boolean, sdkDirectory As String) As CommandLineArguments Implements ICommandLineArgumentsFactoryService.CreateCommandLineArguments
Dim parser = If(isInteractive, VisualBasicCommandLineParser.Interactive, VisualBasicCommandLineParser.Default)
Return parser.Parse(arguments, baseDirectory, sdkDirectory)
End Function
End Class
<ExportLanguageService(GetType(IHostBuildDataFactory), LanguageNames.VisualBasic), [Shared]>
Friend Class VisualBasicHostBuildDataFactory
Implements IHostBuildDataFactory
Public Function Create(options As HostBuildOptions) As HostBuildData Implements IHostBuildDataFactory.Create
Dim parseOptions = VisualBasicParseOptions.Default.WithDocumentationMode(DocumentationMode.Parse)
Dim compilationOptions = New VisualBasicCompilationOptions(OutputKind.ConsoleApplication,
xmlReferenceResolver:=New XmlFileResolver(options.ProjectDirectory),
sourceReferenceResolver:=New SourceFileResolver(ImmutableArray(Of String).Empty, options.ProjectDirectory),
metadataReferenceResolver:=New AssemblyReferenceResolver(
New MetadataFileReferenceResolver(ImmutableArray(Of String).Empty, options.ProjectDirectory),
MetadataFileReferenceProvider.Default),
strongNameProvider:=New DesktopStrongNameProvider(ImmutableArray.Create(Of String)(options.ProjectDirectory, options.OutputDirectory)),
assemblyIdentityComparer:=DesktopAssemblyIdentityComparer.Default)
If Not String.IsNullOrEmpty(options.PlatformWith32BitPreference) Then
Dim plat As Platform
If [Enum].TryParse(options.PlatformWith32BitPreference, True, plat) Then
Dim outputKind = compilationOptions.OutputKind
If plat = Platform.AnyCpu AndAlso outputKind <> OutputKind.DynamicallyLinkedLibrary AndAlso outputKind <> OutputKind.NetModule AndAlso outputKind <> OutputKind.WindowsRuntimeMetadata Then
plat = Platform.AnyCpu32BitPreferred
End If
compilationOptions = compilationOptions.WithPlatform(plat)
End If
End If
Dim warnings = New Dictionary(Of String, ReportDiagnostic)()
If options.OutputKind.HasValue Then
Dim _outputKind = options.OutputKind.Value
compilationOptions = compilationOptions.WithOutputKind(_outputKind)
If compilationOptions.Platform = Platform.AnyCpu32BitPreferred AndAlso
(_outputKind = OutputKind.DynamicallyLinkedLibrary Or _outputKind = OutputKind.NetModule Or _outputKind = OutputKind.WindowsRuntimeMetadata) Then
compilationOptions = compilationOptions.WithPlatform(Platform.AnyCpu)
End If
End If
If Not String.IsNullOrEmpty(options.DefineConstants) Then
Dim errors As IEnumerable(Of Diagnostic) = Nothing
parseOptions = parseOptions.WithPreprocessorSymbols(VisualBasicCommandLineParser.ParseConditionalCompilationSymbols(options.DefineConstants, errors))
End If
If options.DelaySign IsNot Nothing Then
compilationOptions = compilationOptions.WithDelaySign(options.DelaySign.Item1)
End If
If Not String.IsNullOrEmpty(options.DocumentationFile) Then
parseOptions = parseOptions.WithDocumentationMode(DocumentationMode.Diagnose)
Else
parseOptions = parseOptions.WithDocumentationMode(DocumentationMode.Parse)
End If
If options.GlobalImports.Count > 0 Then
Dim e = options.GlobalImports.Select(Function(item) GlobalImport.Parse(item)).AsImmutable()
compilationOptions = compilationOptions.WithGlobalImports(e)
End If
If Not String.IsNullOrEmpty(options.KeyContainer) Then
compilationOptions = compilationOptions.WithCryptoKeyContainer(options.KeyContainer)
End If
If Not String.IsNullOrEmpty(options.KeyFile) Then
compilationOptions = compilationOptions.WithCryptoKeyFile(options.KeyFile)
End If
If Not String.IsNullOrEmpty(options.MainEntryPoint) AndAlso options.MainEntryPoint <> "Sub Main" Then
compilationOptions = compilationOptions.WithMainTypeName(options.MainEntryPoint)
End If
If options.NoWarnings.HasValue Then
compilationOptions = compilationOptions.WithGeneralDiagnosticOption(If(options.NoWarnings.Value, ReportDiagnostic.Suppress, ReportDiagnostic.Warn))
End If
If options.Optimize.HasValue Then
compilationOptions = compilationOptions.WithOptimizationLevel(If(options.Optimize, OptimizationLevel.Release, OptimizationLevel.Debug))
End If
If Not String.IsNullOrEmpty(options.OptionCompare) Then
compilationOptions = compilationOptions.WithOptionCompareText(options.OptionCompare = "Text")
End If
If options.OptionExplicit.HasValue Then
compilationOptions = compilationOptions.WithOptionExplicit(options.OptionExplicit.Value)
End If
If Not String.IsNullOrEmpty(options.OptionStrict) Then
Dim _optionStrict As OptionStrict = OptionStrict.Custom
If TryGetOptionStrict(options.OptionStrict, _optionStrict) Then
compilationOptions = compilationOptions.WithOptionStrict(_optionStrict)
End If
End If
If Not String.IsNullOrEmpty(options.Platform) Then
Dim plat As Platform
If [Enum].TryParse(options.Platform, plat) Then
compilationOptions = compilationOptions.WithPlatform(plat)
End If
End If
If options.CheckForOverflowUnderflow.HasValue Then
compilationOptions = compilationOptions.WithOverflowChecks(options.CheckForOverflowUnderflow.Value)
End If
If Not String.IsNullOrEmpty(options.RootNamespace) Then
compilationOptions = compilationOptions.WithRootNamespace(options.RootNamespace)
End If
If Not String.IsNullOrEmpty(options.RuleSetFile) Then
Dim fullPath = FileUtilities.ResolveRelativePath(options.RuleSetFile, options.ProjectDirectory)
Dim specificDiagnosticOptions As Dictionary(Of String, ReportDiagnostic) = Nothing
Dim generalDiagnosticOption = RuleSet.GetDiagnosticOptionsFromRulesetFile(fullPath, specificDiagnosticOptions)
compilationOptions = compilationOptions.WithGeneralDiagnosticOption(generalDiagnosticOption)
warnings.AddRange(specificDiagnosticOptions)
End If
If options.WarningsAsErrors.HasValue Then
compilationOptions = compilationOptions.WithGeneralDiagnosticOption(If(options.WarningsAsErrors.Value, ReportDiagnostic.Error, ReportDiagnostic.Warn))
End If
If options.OptionInfer.HasValue Then
compilationOptions = compilationOptions.WithOptionInfer(options.OptionInfer.Value)
End If
If options.VBRuntime = "Embed" Then
compilationOptions = compilationOptions.WithEmbedVbCoreRuntime(True)
End If
If Not String.IsNullOrEmpty(options.LanguageVersion) Then
Dim version As Integer
If Int32.TryParse(options.LanguageVersion, version) Then
Dim lv As LanguageVersion = CType(version, LanguageVersion)
If [Enum].IsDefined(GetType(LanguageVersion), lv) Then
parseOptions = parseOptions.WithLanguageVersion(lv)
End If
End If
End If
parseOptions = parseOptions.WithPreprocessorSymbols(AddPredefinedPreprocessorSymbols(compilationOptions.OutputKind, parseOptions.PreprocessorSymbols))
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(warnings)
Return New HostBuildData(parseOptions, compilationOptions)
End Function
Private Shared Function TryGetOptionStrict(text As String, ByRef optionStrictType As OptionStrict) As Boolean
If text = "On" Then
optionStrictType = OptionStrict.On
Return True
ElseIf text = "Off" OrElse text = "Custom" Then
optionStrictType = OptionStrict.Custom
Return True
Else
Return False
End If
End Function
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册