diff --git a/src/Compilers/Helpers/GlobalAssemblyCacheHelpers/GacFileResolver.cs b/src/Compilers/Helpers/GlobalAssemblyCacheHelpers/GacFileResolver.cs
index 909fe3f9ccca3545b865203277e4e702e907853c..218dbdc55548e2f87d85170fe45b9a52a2c62d59 100644
--- a/src/Compilers/Helpers/GlobalAssemblyCacheHelpers/GacFileResolver.cs
+++ b/src/Compilers/Helpers/GlobalAssemblyCacheHelpers/GacFileResolver.cs
@@ -11,7 +11,7 @@
namespace Microsoft.CodeAnalysis.Scripting
{
///
- /// Extends to enable resolution of assembly
+ /// Extends MetadataFileReferenceResolver to enable resolution of assembly
/// simple names in the GAC.
///
internal sealed class GacFileResolver : MetadataFileReferenceResolver
diff --git a/src/Workspaces/CSharp/Desktop/CSharpWorkspace.Desktop.csproj b/src/Workspaces/CSharp/Desktop/CSharpWorkspace.Desktop.csproj
index 9bea88aa9971da5ff17b164516364846319b580a..30df58ee1ba56d2c9ba129f36c0e48c7370fc44c 100644
--- a/src/Workspaces/CSharp/Desktop/CSharpWorkspace.Desktop.csproj
+++ b/src/Workspaces/CSharp/Desktop/CSharpWorkspace.Desktop.csproj
@@ -21,6 +21,7 @@
+
False
..\..\..\..\packages\System.Collections.Immutable.$(SystemCollectionsImmutableVersion)\lib\portable-net45+win8+wp8+wpa81\\System.Collections.Immutable.dll
@@ -51,10 +52,6 @@
{1EE8CAD3-55F9-4D91-96B2-084641DA9A6C}
CodeAnalysis
-
- {B501A547-C911-4A05-AC6E-274A50DFF30E}
- CSharpCodeAnalysis
-
{2e87fa96-50bb-4607-8676-46521599f998}
Workspaces.Desktop
@@ -63,16 +60,6 @@
{5F8D2414-064A-4B3A-9B42-8E2A04246BE5}
Workspaces
-
- {21b239d0-d144-430f-a394-c066d58ee267}
- CSharpWorkspace
-
-
-
-
-
-
-
@@ -90,4 +77,4 @@
-
+
\ No newline at end of file
diff --git a/src/Workspaces/CSharp/Desktop/LanguageServices/CSharpCommandLineArgumentsFactoryService.cs b/src/Workspaces/CSharp/Desktop/LanguageServices/CSharpCommandLineArgumentsFactoryService.cs
deleted file mode 100644
index d9614e3415d597b4e333c26a5c3bc5ebf007c934..0000000000000000000000000000000000000000
--- a/src/Workspaces/CSharp/Desktop/LanguageServices/CSharpCommandLineArgumentsFactoryService.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// 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;
-
-namespace Microsoft.CodeAnalysis.CSharp
-{
- [ExportLanguageService(typeof(ICommandLineArgumentsFactoryService), LanguageNames.CSharp), Shared]
- internal class CSharpCommandLineArgumentsFactoryService : ICommandLineArgumentsFactoryService
- {
- public CommandLineArguments CreateCommandLineArguments(IEnumerable arguments, string baseDirectory, bool isInteractive)
- {
- var parser = isInteractive ? CSharpCommandLineParser.Interactive : CSharpCommandLineParser.Default;
- return parser.Parse(arguments, baseDirectory, RuntimeEnvironment.GetRuntimeDirectory());
- }
- }
-}
diff --git a/src/Workspaces/CSharp/Portable/CSharpWorkspace.csproj b/src/Workspaces/CSharp/Portable/CSharpWorkspace.csproj
index 04308e44985ebd81cf770f61ab6353665d1721e7..8c1d1c60799a2b59d98a7710eb8e11dc1ae6cf63 100644
--- a/src/Workspaces/CSharp/Portable/CSharpWorkspace.csproj
+++ b/src/Workspaces/CSharp/Portable/CSharpWorkspace.csproj
@@ -117,6 +117,7 @@
+
True
True
@@ -268,4 +269,4 @@
-
\ No newline at end of file
+
diff --git a/src/Workspaces/CSharp/Portable/LanguageServices/CSharpHostBuildDataFactory.cs b/src/Workspaces/CSharp/Portable/LanguageServices/CSharpHostBuildDataFactory.cs
new file mode 100644
index 0000000000000000000000000000000000000000..ac868e896ab3dc1f992784c46a7dc65b8066ed72
--- /dev/null
+++ b/src/Workspaces/CSharp/Portable/LanguageServices/CSharpHostBuildDataFactory.cs
@@ -0,0 +1,181 @@
+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 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.Empty, options.ProjectDirectory),
+ metadataReferenceResolver: new AssemblyReferenceResolver(
+ new MetadataFileReferenceResolver(ImmutableArray.Empty, options.ProjectDirectory),
+ MetadataFileReferenceProvider.Default),
+ strongNameProvider: new DesktopStrongNameProvider(ImmutableArray.Create(options.ProjectDirectory, options.OutputDirectory)),
+ assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default);
+ var warnings = new List>(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 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(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(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 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);
+ }
+ }
+}
diff --git a/src/Workspaces/Core/Desktop/Workspace/CommandLineProject.cs b/src/Workspaces/Core/Desktop/Workspace/CommandLineProject.cs
index 137546414622fab7c770708eae521ba26fc135d0..5b42026628df9cca69e7f9bf66ee88c0ccf16dc4 100644
--- a/src/Workspaces/Core/Desktop/Workspace/CommandLineProject.cs
+++ b/src/Workspaces/Core/Desktop/Workspace/CommandLineProject.cs
@@ -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();
- 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);
diff --git a/src/Workspaces/CSharp/Desktop/MSBuild/CSharpProjectFileLoader.CSharpProjectFile.cs b/src/Workspaces/Core/Desktop/Workspace/MSBuild/CSharp/CSharpProjectFileLoader.CSharpProjectFile.cs
similarity index 73%
rename from src/Workspaces/CSharp/Desktop/MSBuild/CSharpProjectFileLoader.CSharpProjectFile.cs
rename to src/Workspaces/Core/Desktop/Workspace/MSBuild/CSharp/CSharpProjectFileLoader.CSharpProjectFile.cs
index 3b8f65fdfa39008b5e4897030d4e5854a563cbfc..d4a14bb3c754ac09af68f238bfdb6700d727b0da 100644
--- a/src/Workspaces/CSharp/Desktop/MSBuild/CSharpProjectFileLoader.CSharpProjectFile.cs
+++ b/src/Workspaces/Core/Desktop/Workspace/MSBuild/CSharp/CSharpProjectFileLoader.CSharpProjectFile.cs
@@ -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 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 Sources { get; private set; }
internal IEnumerable References { get; private set; }
@@ -280,33 +282,20 @@ private class CSharpCompilerInputs :
internal IEnumerable AdditionalFiles { get; private set; }
internal IReadOnlyList LibPaths { get; private set; }
internal bool NoStandardLib { get; private set; }
- internal Dictionary 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.Empty, projectDirectory),
- metadataReferenceResolver: new AssemblyReferenceResolver(
- new MetadataFileReferenceResolver(ImmutableArray.Empty, projectDirectory),
- MetadataFileReferenceProvider.Default),
- strongNameProvider: new DesktopStrongNameProvider(ImmutableArray.Create(projectDirectory, outputDirectory)),
- assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default);
- this.Warnings = new Dictionary();
+ this.Options = new HostBuildOptions();
this.Sources = SpecializedCollections.EmptyEnumerable();
this.References = SpecializedCollections.EmptyEnumerable();
this.AnalyzerReferences = SpecializedCollections.EmptyEnumerable();
this.AdditionalFiles = SpecializedCollections.EmptyEnumerable();
this.LibPaths = SpecializedCollections.EmptyReadOnlyList();
+
+ 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(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 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, 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 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;
}
diff --git a/src/Workspaces/CSharp/Desktop/MSBuild/CSharpProjectFileLoader.cs b/src/Workspaces/Core/Desktop/Workspace/MSBuild/CSharp/CSharpProjectFileLoader.cs
similarity index 72%
rename from src/Workspaces/CSharp/Desktop/MSBuild/CSharpProjectFileLoader.cs
rename to src/Workspaces/Core/Desktop/Workspace/MSBuild/CSharp/CSharpProjectFileLoader.cs
index 587a381b5682ac44e72da11116545f583d8672cf..3c5bfdd44dbdfcd642bebcf5909fe38e2b81d13a 100644
--- a/src/Workspaces/CSharp/Desktop/MSBuild/CSharpProjectFileLoader.cs
+++ b/src/Workspaces/Core/Desktop/Workspace/MSBuild/CSharp/CSharpProjectFileLoader.cs
@@ -23,6 +23,16 @@ public override string Language
get { return LanguageNames.CSharp; }
}
+ public IHostBuildDataFactory MSBuildHost
+ {
+ get { return _workspaceServices.GetLanguageServices(Language).GetService(); }
+ }
+
+ public ICommandLineArgumentsFactoryService CommandLineArgumentsFactoryService
+ {
+ get { return _workspaceServices.GetLanguageServices(Language).GetService(); }
+ }
+
protected override ProjectFile CreateProjectFile(MSB.Evaluation.Project loadedProject)
{
return new CSharpProjectFile(this, loadedProject, _workspaceServices.GetService(), _workspaceServices.GetService());
diff --git a/src/Workspaces/CSharp/Desktop/MSBuild/CSharpProjectFileLoaderFactory.cs b/src/Workspaces/Core/Desktop/Workspace/MSBuild/CSharp/CSharpProjectFileLoaderFactory.cs
similarity index 100%
rename from src/Workspaces/CSharp/Desktop/MSBuild/CSharpProjectFileLoaderFactory.cs
rename to src/Workspaces/Core/Desktop/Workspace/MSBuild/CSharp/CSharpProjectFileLoaderFactory.cs
diff --git a/src/Workspaces/Core/Desktop/Workspace/MSBuild/VisualBasic/VisualBasicProjectFileLoader.cs b/src/Workspaces/Core/Desktop/Workspace/MSBuild/VisualBasic/VisualBasicProjectFileLoader.cs
new file mode 100644
index 0000000000000000000000000000000000000000..b958a3ceaed75bf57ba165a7ba0d49f169290a28
--- /dev/null
+++ b/src/Workspaces/Core/Desktop/Workspace/MSBuild/VisualBasic/VisualBasicProjectFileLoader.cs
@@ -0,0 +1,774 @@
+// 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;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Build.Evaluation;
+using Microsoft.Build.Execution;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Tasks.Hosting;
+using Microsoft.CodeAnalysis.Diagnostics;
+using Microsoft.CodeAnalysis.Host;
+using Microsoft.CodeAnalysis.MSBuild;
+using Roslyn.Utilities;
+using MSB = Microsoft.Build;
+
+namespace Microsoft.CodeAnalysis.VisualBasic
+{
+ internal class VisualBasicProjectFileLoader : ProjectFileLoader
+ {
+ private readonly HostWorkspaceServices _workspaceServices;
+
+ internal HostLanguageServices LanguageServices
+ {
+ get { return this._workspaceServices.GetLanguageServices(LanguageNames.VisualBasic); }
+ }
+
+ public override string Language
+ {
+ get { return LanguageNames.VisualBasic; }
+ }
+
+ internal VisualBasicProjectFileLoader(HostWorkspaceServices workspaceServices)
+ {
+ this._workspaceServices = workspaceServices;
+ }
+
+ protected override ProjectFile CreateProjectFile(MSB.Evaluation.Project loadedProject)
+ {
+ return new VisualBasicProjectFile(this, loadedProject, this._workspaceServices.GetService(), this._workspaceServices.GetService());
+ }
+
+ internal class VisualBasicProjectFile : ProjectFile
+ {
+ private readonly IMetadataService _metadataService;
+ private readonly IAnalyzerService _analyzerService;
+ private readonly IHostBuildDataFactory _hostBuildDataFactory;
+ private readonly ICommandLineArgumentsFactoryService _commandLineArgumentsFactory;
+
+ public VisualBasicProjectFile(VisualBasicProjectFileLoader loader, MSB.Evaluation.Project loadedProject, IMetadataService metadataService, IAnalyzerService analyzerService) : base(loader, loadedProject)
+ {
+ this._metadataService = metadataService;
+ this._analyzerService = analyzerService;
+ this._hostBuildDataFactory = loader.LanguageServices.GetService();
+ this._commandLineArgumentsFactory = loader.LanguageServices.GetService();
+ }
+
+ public override SourceCodeKind GetSourceCodeKind(string documentFileName)
+ {
+ SourceCodeKind result;
+ if (documentFileName.EndsWith(".vbx", StringComparison.OrdinalIgnoreCase))
+ {
+ result = SourceCodeKind.Script;
+ }
+ else
+ {
+ result = SourceCodeKind.Regular;
+ }
+ return result;
+ }
+
+ public override string GetDocumentExtension(SourceCodeKind sourceCodeKind)
+ {
+ string result;
+ if (sourceCodeKind != SourceCodeKind.Script)
+ {
+ result = ".vb";
+ }
+ else
+ {
+ result = ".vbx";
+ }
+ return result;
+ }
+
+ public override async Task GetProjectFileInfoAsync(CancellationToken cancellationToken)
+ {
+ var compilerInputs = new VisualBasicCompilerInputs(this);
+ var executedProject = await BuildAsync("Vbc", compilerInputs, cancellationToken).ConfigureAwait(false);
+
+ if (!compilerInputs.Initialized)
+ {
+ InitializeFromModel(compilerInputs, executedProject);
+ }
+
+ return CreateProjectFileInfo(compilerInputs, executedProject);
+ }
+
+ private ProjectFileInfo CreateProjectFileInfo(VisualBasicProjectFileLoader.VisualBasicProjectFile.VisualBasicCompilerInputs compilerInputs, ProjectInstance executedProject)
+ {
+ IEnumerable metadataReferences = null;
+ IEnumerable analyzerReferences = null;
+ this.GetReferences(compilerInputs, executedProject, ref metadataReferences, ref analyzerReferences);
+ string outputPath = Path.Combine(this.GetOutputDirectory(), compilerInputs.OutputFileName);
+ string assemblyName = this.GetAssemblyName();
+ HostBuildData hostBuildData = this._hostBuildDataFactory.Create(compilerInputs.HostBuildOptions);
+ return new ProjectFileInfo(outputPath, assemblyName, hostBuildData.CompilationOptions, hostBuildData.ParseOptions, compilerInputs.CodePage, this.GetDocuments(compilerInputs.Sources, executedProject), this.GetDocuments(compilerInputs.AdditionalFiles, executedProject), base.GetProjectReferences(executedProject), metadataReferences, analyzerReferences);
+ }
+
+ private void GetReferences(VisualBasicProjectFileLoader.VisualBasicProjectFile.VisualBasicCompilerInputs compilerInputs, ProjectInstance executedProject, ref IEnumerable metadataReferences, ref IEnumerable analyzerReferences)
+ {
+
+ // use command line parser to compute references using common logic
+ List list = new List();
+ if (compilerInputs.LibPaths != null && compilerInputs.LibPaths.Count() > 0)
+ {
+ list.Add("/libpath:\"" + string.Join(";", compilerInputs.LibPaths) + "\"");
+ }
+
+ // metadata references
+ foreach (var current in compilerInputs.References)
+ {
+ string documentFilePath = base.GetDocumentFilePath(current);
+ list.Add("/r:\"" + documentFilePath + "\"");
+ }
+
+ // analyzer references
+ foreach (var current in compilerInputs.AnalyzerReferences)
+ {
+ string documentFilePath2 = base.GetDocumentFilePath(current);
+ list.Add("/a:\"" + documentFilePath2 + "\"");
+ }
+
+ if (compilerInputs.NoStandardLib)
+ {
+ list.Add("/nostdlib");
+ }
+
+ if (!string.IsNullOrEmpty(compilerInputs.VbRuntime))
+ {
+ if (compilerInputs.VbRuntime == "Default")
+ {
+ list.Add("/vbruntime+");
+ }
+ else if (compilerInputs.VbRuntime == "Embed")
+ {
+ list.Add("/vbruntime*");
+ }
+ else if (compilerInputs.VbRuntime == "None")
+ {
+ list.Add("/vbruntime-");
+ }
+ else
+ {
+ list.Add("/vbruntime: " + compilerInputs.VbRuntime);
+ }
+ }
+
+ if (!string.IsNullOrEmpty(compilerInputs.SdkPath))
+ {
+ list.Add("/sdkpath:" + compilerInputs.SdkPath);
+ }
+
+ CommandLineArguments commandLineArguments = this._commandLineArgumentsFactory.CreateCommandLineArguments(list, executedProject.Directory, false, RuntimeEnvironment.GetRuntimeDirectory());
+ MetadataFileReferenceResolver pathResolver = new MetadataFileReferenceResolver(commandLineArguments.ReferencePaths, commandLineArguments.BaseDirectory);
+ metadataReferences = commandLineArguments.ResolveMetadataReferences(new AssemblyReferenceResolver(pathResolver, this._metadataService.GetProvider()));
+
+ IAnalyzerAssemblyLoader loader = this._analyzerService.GetLoader();
+ foreach (var path in commandLineArguments.AnalyzerReferences.Select((r) => r.FilePath))
+ {
+ loader.AddDependencyLocation(path);
+ }
+
+ analyzerReferences = commandLineArguments.ResolveAnalyzerReferences(loader);
+ }
+
+ private IEnumerable GetDocuments(IEnumerable sources, ProjectInstance executedProject)
+ {
+ IEnumerable result;
+ if (sources == null)
+ {
+ result = ImmutableArray.Empty;
+ }
+
+ var projectDirectory = executedProject.Directory;
+ if (!projectDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase))
+ {
+ projectDirectory += Path.DirectorySeparatorChar;
+ }
+
+ return sources
+ .Where(s => !System.IO.Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal))
+ .Select(s => new DocumentFileInfo(GetDocumentFilePath(s), GetDocumentLogicalPath(s, projectDirectory), IsDocumentLinked(s), IsDocumentGenerated(s))).ToImmutableArray();
+ }
+
+ private void InitializeFromModel(VisualBasicProjectFileLoader.VisualBasicProjectFile.VisualBasicCompilerInputs compilerInputs, ProjectInstance executedProject)
+ {
+ compilerInputs.BeginInitialization();
+ compilerInputs.SetBaseAddress(base.ReadPropertyString(executedProject, "OutputType"), base.ReadPropertyString(executedProject, "BaseAddress"));
+ compilerInputs.SetCodePage(base.ReadPropertyInt(executedProject, "CodePage"));
+ compilerInputs.SetDebugType(base.ReadPropertyBool(executedProject, "DebugSymbols"), base.ReadPropertyString(executedProject, "DebugType"));
+ compilerInputs.SetDefineConstants(base.ReadPropertyString(executedProject, "FinalDefineConstants", "DefineConstants"));
+ compilerInputs.SetDelaySign(base.ReadPropertyBool(executedProject, "DelaySign"));
+ compilerInputs.SetDisabledWarnings(base.ReadPropertyString(executedProject, "NoWarn"));
+ compilerInputs.SetDocumentationFile(base.GetItemString(executedProject, "DocFileItem"));
+ compilerInputs.SetErrorReport(base.ReadPropertyString(executedProject, "ErrorReport"));
+ compilerInputs.SetFileAlignment(base.ReadPropertyInt(executedProject, "FileAlignment"));
+ compilerInputs.SetGenerateDocumentation(base.ReadPropertyBool(executedProject, "GenerateDocumentation"));
+ compilerInputs.SetHighEntropyVA(base.ReadPropertyBool(executedProject, "HighEntropyVA"));
+
+ var _imports = this.GetTaskItems(executedProject, "Import");
+ if (_imports != null)
+ {
+ compilerInputs.SetImports(_imports.ToArray());
+ }
+
+ var signAssembly = ReadPropertyBool(executedProject, "SignAssembly");
+ if (signAssembly)
+ {
+ var keyFile = ReadPropertyString(executedProject, "KeyOriginatorFile", "AssemblyOriginatorKeyFile");
+ if (!string.IsNullOrEmpty(keyFile))
+ {
+ compilerInputs.SetKeyFile(keyFile);
+ }
+
+ var keyContainer = ReadPropertyString(executedProject, "KeyContainerName");
+ if (!string.IsNullOrEmpty(keyContainer))
+ {
+ compilerInputs.SetKeyContainer(keyContainer);
+ }
+ }
+
+ compilerInputs.SetLanguageVersion(base.ReadPropertyString(executedProject, "LangVersion"));
+ compilerInputs.SetMainEntryPoint(base.ReadPropertyString(executedProject, "StartupObject"));
+ compilerInputs.SetModuleAssemblyName(base.ReadPropertyString(executedProject, "ModuleEntryPoint"));
+ compilerInputs.SetNoStandardLib(base.ReadPropertyBool(executedProject, "NoCompilerStandardLib", "NoStdLib"));
+ compilerInputs.SetNoWarnings(base.ReadPropertyBool(executedProject, "_NoWarnings"));
+ compilerInputs.SetOptimize(base.ReadPropertyBool(executedProject, "Optimize"));
+ compilerInputs.SetOptionCompare(base.ReadPropertyString(executedProject, "OptionCompare"));
+ compilerInputs.SetOptionExplicit(base.ReadPropertyBool(executedProject, "OptionExplicit"));
+ compilerInputs.SetOptionInfer(base.ReadPropertyBool(executedProject, "OptionInfer"));
+ compilerInputs.SetOptionStrictType(base.ReadPropertyString(executedProject, "OptionStrict"));
+ compilerInputs.SetOutputAssembly(base.GetItemString(executedProject, "IntermediateAssembly"));
+
+ if (base.ReadPropertyBool(executedProject, "Prefer32Bit"))
+ {
+ compilerInputs.SetPlatformWith32BitPreference(base.ReadPropertyString(executedProject, "PlatformTarget"));
+ }
+ else
+ {
+ compilerInputs.SetPlatform(base.ReadPropertyString(executedProject, "PlatformTarget"));
+ }
+
+ compilerInputs.SetRemoveIntegerChecks(base.ReadPropertyBool(executedProject, "RemoveIntegerChecks"));
+ compilerInputs.SetRootNamespace(base.ReadPropertyString(executedProject, "RootNamespace"));
+ compilerInputs.SetSdkPath(base.ReadPropertyString(executedProject, "FrameworkPathOverride"));
+ compilerInputs.SetSubsystemVersion(base.ReadPropertyString(executedProject, "SubsystemVersion"));
+ compilerInputs.SetTargetCompactFramework(base.ReadPropertyBool(executedProject, "TargetCompactFramework"));
+ compilerInputs.SetTargetType(base.ReadPropertyString(executedProject, "OutputType"));
+
+ // Decode the warning options from RuleSet file prior to reading explicit settings in the project file, so that project file settings prevail for duplicates.
+ compilerInputs.SetRuleSet(base.ReadPropertyString(executedProject, "RuleSet"));
+
+ compilerInputs.SetTreatWarningsAsErrors(base.ReadPropertyBool(executedProject, "SetTreatWarningsAsErrors"));
+ compilerInputs.SetVBRuntime(base.ReadPropertyString(executedProject, "VbRuntime"));
+ compilerInputs.SetWarningsAsErrors(base.ReadPropertyString(executedProject, "WarningsAsErrors"));
+ compilerInputs.SetWarningsNotAsErrors(base.ReadPropertyString(executedProject, "WarningsNotAsErrors"));
+ compilerInputs.SetReferences(this.GetMetadataReferencesFromModel(executedProject).ToArray());
+ compilerInputs.SetAnalyzers(this.GetAnalyzerReferencesFromModel(executedProject).ToArray());
+ compilerInputs.SetAdditionalFiles(this.GetAdditionalFilesFromModel(executedProject).ToArray());
+ compilerInputs.SetSources(this.GetDocumentsFromModel(executedProject).ToArray());
+ compilerInputs.EndInitialization();
+ }
+
+ private class VisualBasicCompilerInputs :
+ MSB.Tasks.Hosting.IVbcHostObject5,
+ MSB.Tasks.Hosting.IVbcHostObjectFreeThreaded
+#if !MSBUILD12
+ ,IAnalyzerHostObject
+#endif
+ {
+ private readonly VisualBasicProjectFile _projectFile;
+ private bool _initialized;
+ private HostBuildOptions _options;
+ private int _codePage;
+ private IEnumerable _sources;
+ private IEnumerable _additionalFiles;
+ private IEnumerable _references;
+ private IEnumerable _analyzerReferences;
+ private bool _noStandardLib;
+ private readonly Dictionary _warnings;
+ private string _sdkPath;
+ private bool _targetCompactFramework;
+ private string _vbRuntime;
+ private IEnumerable _libPaths;
+
+ private string _outputFileName;
+ public VisualBasicCompilerInputs(VisualBasicProjectFile projectFile)
+ {
+ this._projectFile = projectFile;
+ this._options = new HostBuildOptions();
+ this._sources = SpecializedCollections.EmptyEnumerable();
+ this._references = SpecializedCollections.EmptyEnumerable();
+ this._analyzerReferences = SpecializedCollections.EmptyEnumerable();
+ this._warnings = new Dictionary();
+
+ this._options.ProjectDirectory = Path.GetDirectoryName(projectFile.FilePath);
+ this._options.OutputDirectory = projectFile.GetOutputDirectory();
+ }
+
+ public bool Initialized
+ {
+ get { return this._initialized; }
+ }
+
+ public HostBuildOptions HostBuildOptions
+ {
+ get { return this._options; }
+ }
+
+ public int CodePage
+ {
+ get { return this._codePage; }
+ }
+
+ public IEnumerable References
+ {
+ get { return this._references; }
+ }
+
+ public IEnumerable AnalyzerReferences
+ {
+ get { return this._analyzerReferences; }
+ }
+
+ public IEnumerable Sources
+ {
+ get { return this._sources; }
+ }
+
+ public IEnumerable AdditionalFiles
+ {
+ get { return this._additionalFiles; }
+ }
+
+ public bool NoStandardLib
+ {
+ get { return this._noStandardLib; }
+ }
+
+ public string VbRuntime
+ {
+ get { return this._vbRuntime; }
+ }
+
+ public string SdkPath
+ {
+ get { return this._sdkPath; }
+ }
+
+ public bool TargetCompactFramework
+ {
+ get { return this._targetCompactFramework; }
+ }
+
+ public IEnumerable LibPaths
+ {
+ get { return this._libPaths; }
+ }
+
+ public string OutputFileName
+ {
+ get { return this._outputFileName; }
+ }
+
+ public void BeginInitialization()
+ {
+ }
+
+ public bool Compile()
+ {
+ return false;
+ }
+
+ public void EndInitialization()
+ {
+ this._initialized = true;
+ }
+
+ public bool IsDesignTime()
+ {
+ return true;
+ }
+
+ public bool IsUpToDate()
+ {
+ return true;
+ }
+
+ public bool SetAdditionalLibPaths(string[] additionalLibPaths)
+ {
+ this._libPaths = additionalLibPaths;
+ return true;
+ }
+
+ public bool SetAddModules(string[] addModules)
+ {
+ return true;
+ }
+
+ public bool SetBaseAddress(string targetType, string baseAddress)
+ {
+ // we don't capture emit options
+ return true;
+ }
+
+ public bool SetCodePage(int codePage)
+ {
+ this._codePage = codePage;
+ return true;
+ }
+
+ public bool SetDebugType(bool emitDebugInformation, string debugType)
+ {
+ // ignore, just check for expected values for backwards compat
+ return string.Equals(debugType, "none", StringComparison.OrdinalIgnoreCase) || string.Equals(debugType, "pdbonly", StringComparison.OrdinalIgnoreCase) || string.Equals(debugType, "full", StringComparison.OrdinalIgnoreCase);
+ }
+
+ public bool SetDefineConstants(string defineConstants)
+ {
+ this._options.DefineConstants = defineConstants;
+ return true;
+ }
+
+ public bool SetDelaySign(bool delaySign)
+ {
+ this._options.DelaySign = Tuple.Create(delaySign, false);
+ return true;
+ }
+
+ public bool SetDisabledWarnings(string disabledWarnings)
+ {
+ SetWarnings(disabledWarnings, ReportDiagnostic.Suppress);
+ return true;
+ }
+
+ public bool SetDocumentationFile(string documentationFile)
+ {
+ this._options.DocumentationFile = documentationFile;
+ return true;
+ }
+
+ public bool SetErrorReport(string errorReport)
+ {
+ // ??
+ return true;
+ }
+
+ public bool SetFileAlignment(int fileAlignment)
+ {
+ // we don't capture emit options
+ return true;
+ }
+
+ public bool SetGenerateDocumentation(bool generateDocumentation)
+ {
+ return true;
+ }
+
+ public bool SetImports(Microsoft.Build.Framework.ITaskItem[] importsList)
+ {
+ if (importsList != null)
+ {
+ _options.GlobalImports.AddRange(importsList.Select(item => item.ItemSpec.Trim()));
+ }
+ return true;
+ }
+
+ public bool SetKeyContainer(string keyContainer)
+ {
+ this._options.KeyContainer = keyContainer;
+ return true;
+ }
+
+ public bool SetKeyFile(string keyFile)
+ {
+ this._options.KeyFile = keyFile;
+ return true;
+ }
+
+ public bool SetLinkResources(Microsoft.Build.Framework.ITaskItem[] linkResources)
+ {
+ // ??
+ return true;
+ }
+
+ public bool SetMainEntryPoint(string mainEntryPoint)
+ {
+ this._options.MainEntryPoint = mainEntryPoint;
+ return true;
+ }
+
+ public bool SetNoConfig(bool noConfig)
+ {
+ return true;
+ }
+
+ public bool SetNoStandardLib(bool noStandardLib)
+ {
+ this._noStandardLib = noStandardLib;
+ return true;
+ }
+
+ public bool SetNoWarnings(bool noWarnings)
+ {
+ this._options.NoWarnings = noWarnings;
+ return true;
+ }
+
+ public bool SetOptimize(bool optimize)
+ {
+ this._options.Optimize = optimize;
+ return true;
+ }
+
+ public bool SetOptionCompare(string optionCompare)
+ {
+ this._options.OptionCompare = optionCompare;
+ return true;
+ }
+
+ public bool SetOptionExplicit(bool optionExplicit)
+ {
+ this._options.OptionExplicit = optionExplicit;
+ return true;
+ }
+
+ public bool SetOptionStrict(bool _optionStrict)
+ {
+ this._options.OptionStrict = _optionStrict ? "On" : "Custom";
+ return true;
+ }
+
+ public bool SetOptionStrictType(string optionStrictType)
+ {
+ if (!string.IsNullOrEmpty(optionStrictType))
+ {
+ this._options.OptionStrict = optionStrictType;
+ }
+ return true;
+ }
+
+ public bool SetOutputAssembly(string outputAssembly)
+ {
+ this._outputFileName = Path.GetFileName(outputAssembly);
+ return true;
+ }
+
+ public bool SetPlatform(string _platform)
+ {
+ this._options.Platform = _platform;
+ return true;
+ }
+
+ public bool SetPlatformWith32BitPreference(string _platform)
+ {
+ this._options.PlatformWith32BitPreference = _platform;
+ return true;
+ }
+
+ public bool SetReferences(Microsoft.Build.Framework.ITaskItem[] references)
+ {
+ this._references = references ?? SpecializedCollections.EmptyEnumerable();
+ return true;
+ }
+
+ public bool SetAnalyzers(MSB.Framework.ITaskItem[] analyzerReferences)
+ {
+ this._analyzerReferences = analyzerReferences ?? SpecializedCollections.EmptyEnumerable();
+ return true;
+ }
+
+ public bool SetAdditionalFiles(MSB.Framework.ITaskItem[] additionalFiles)
+ {
+ this._additionalFiles = additionalFiles ?? SpecializedCollections.EmptyEnumerable();
+ return true;
+ }
+
+ public bool SetRemoveIntegerChecks(bool removeIntegerChecks)
+ {
+ this._options.CheckForOverflowUnderflow = !removeIntegerChecks;
+ return true;
+ }
+
+ public bool SetResources(Microsoft.Build.Framework.ITaskItem[] resources)
+ {
+ return true;
+ }
+
+ public bool SetResponseFiles(Microsoft.Build.Framework.ITaskItem[] responseFiles)
+ {
+ return true;
+ }
+
+ public bool SetRootNamespace(string rootNamespace)
+ {
+ this._options.RootNamespace = rootNamespace;
+ return true;
+ }
+
+ public bool SetSdkPath(string sdkPath)
+ {
+ this._sdkPath = sdkPath;
+ return true;
+ }
+
+ public bool SetSources(Microsoft.Build.Framework.ITaskItem[] sources)
+ {
+ this._sources = sources ?? SpecializedCollections.EmptyEnumerable();
+ return true;
+ }
+
+ public bool SetTargetCompactFramework(bool targetCompactFramework)
+ {
+ this._targetCompactFramework = targetCompactFramework;
+ return true;
+ }
+
+ public bool SetTargetType(string targetType)
+ {
+ if (!string.IsNullOrEmpty(targetType))
+ {
+ OutputKind outputKind;
+ if (VisualBasicProjectFile.TryGetOutputKind(targetType, out outputKind))
+ {
+ this._options.OutputKind = outputKind;
+ }
+ }
+ return true;
+ }
+
+ public bool SetRuleSet(string ruleSetFile)
+ {
+ this._options.RuleSetFile = ruleSetFile;
+ return true;
+ }
+
+ public bool SetTreatWarningsAsErrors(bool treatWarningsAsErrors)
+ {
+ this._options.WarningsAsErrors = treatWarningsAsErrors;
+ return true;
+ }
+
+ public bool SetWarningsAsErrors(string warningsAsErrors)
+ {
+ SetWarnings(warningsAsErrors, ReportDiagnostic.Error);
+ return true;
+ }
+
+ private static readonly char[] s_warningSeparators = { ';', ',' };
+
+ private void SetWarnings(string warnings, ReportDiagnostic reportStyle)
+ {
+ if (!string.IsNullOrEmpty(warnings))
+ {
+ foreach (var warning in warnings.Split(s_warningSeparators, StringSplitOptions.None))
+ {
+ int warningId = 0;
+ if (Int32.TryParse(warning, out warningId))
+ {
+ this._warnings["BC" + warningId.ToString("0000")] = reportStyle;
+ }
+ else
+ {
+ this._warnings[warning] = reportStyle;
+ }
+ }
+ }
+ }
+
+ public bool SetWarningsNotAsErrors(string warningsNotAsErrors)
+ {
+ SetWarnings(warningsNotAsErrors, ReportDiagnostic.Warn);
+ return true;
+ }
+
+ public bool SetWin32Icon(string win32Icon)
+ {
+ return true;
+ }
+
+ public bool SetWin32Resource(string win32Resource)
+ {
+ return true;
+ }
+
+ public bool SetModuleAssemblyName(string moduleAssemblyName)
+ {
+ return true;
+ }
+
+ public bool SetOptionInfer(bool optionInfer)
+ {
+ this._options.OptionInfer = optionInfer;
+ return true;
+ }
+
+ public bool SetWin32Manifest(string win32Manifest)
+ {
+ return true;
+ }
+
+ public bool SetLanguageVersion(string _languageVersion)
+ {
+ this._options.LanguageVersion = _languageVersion;
+ return true;
+ }
+
+ public bool SetVBRuntime(string VBRuntime)
+ {
+ this._vbRuntime = VBRuntime;
+ this._options.VBRuntime = VBRuntime;
+ return true;
+ }
+
+ public int CompileAsync(out IntPtr buildSucceededEvent, out IntPtr buildFailedEvent)
+ {
+ buildSucceededEvent = IntPtr.Zero;
+ buildFailedEvent = IntPtr.Zero;
+ return 0;
+ }
+
+ public int EndCompile(bool buildSuccess)
+ {
+ return 0;
+ }
+
+ public Microsoft.Build.Tasks.Hosting.IVbcHostObjectFreeThreaded GetFreeThreadedHostObject()
+ {
+ return null;
+ }
+
+ public bool SetHighEntropyVA(bool highEntropyVA)
+ {
+ // we don't capture emit options
+ return true;
+ }
+
+ public bool SetSubsystemVersion(string subsystemVersion)
+ {
+ // we don't capture emit options
+ return true;
+ }
+
+ public bool Compile1()
+ {
+ return false;
+ }
+ bool Microsoft.Build.Tasks.Hosting.IVbcHostObjectFreeThreaded.Compile()
+ {
+ return Compile1();
+ }
+ }
+
+
+ }
+ }
+}
diff --git a/src/Workspaces/Core/Desktop/Workspace/MSBuild/VisualBasic/VisualBasicProjectFileLoaderFactory.cs b/src/Workspaces/Core/Desktop/Workspace/MSBuild/VisualBasic/VisualBasicProjectFileLoaderFactory.cs
new file mode 100644
index 0000000000000000000000000000000000000000..99e574148fe2943a50d0a0506bb13c3dd2533566
--- /dev/null
+++ b/src/Workspaces/Core/Desktop/Workspace/MSBuild/VisualBasic/VisualBasicProjectFileLoaderFactory.cs
@@ -0,0 +1,20 @@
+// 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.Composition;
+using Microsoft.CodeAnalysis.Host;
+using Microsoft.CodeAnalysis.Host.Mef;
+using Microsoft.CodeAnalysis.MSBuild;
+
+namespace Microsoft.CodeAnalysis.VisualBasic
+{
+ [ExportLanguageServiceFactory(typeof(IProjectFileLoader), LanguageNames.VisualBasic), Shared()]
+ [ProjectFileExtension("vbproj")]
+ [ProjectTypeGuid("F184B08F-C81C-45F6-A57F-5ABD9991F28F")]
+ internal class VisualBasicProjectFileLoaderFactory : ILanguageServiceFactory
+ {
+ public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
+ {
+ return new VisualBasicProjectFileLoader(languageServices.WorkspaceServices);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Workspaces/Core/Desktop/Workspaces.Desktop.csproj b/src/Workspaces/Core/Desktop/Workspaces.Desktop.csproj
index 77596da7d7938d7eb8bddbc3bda6b6aa9ab2a9af..1f0acfdaa5bd1510723d53447f2fb666d6fb9fce 100644
--- a/src/Workspaces/Core/Desktop/Workspaces.Desktop.csproj
+++ b/src/Workspaces/Core/Desktop/Workspaces.Desktop.csproj
@@ -55,34 +55,17 @@
+
-
- InternalUtilities\AssemblyReferenceResolver.cs
-
-
- InternalUtilities\MetadataFileReferenceResolver.cs
-
InternalUtilities\EncodedStringText.cs
InternalUtilities\FileKey.cs
-
- InternalUtilities\ReflectionUtil.cs
-
-
- InternalUtilities\PortableShim.cs
-
-
- InternalUtilities\FileUtilities.cs
-
-
- InternalUtilities\PathUtilities.cs
-
InternalUtilities\AbstractAnalyzerAssemblyLoader.cs
@@ -115,7 +98,6 @@
-
@@ -123,6 +105,9 @@
+
+
+
@@ -138,6 +123,8 @@
+
+
@@ -189,4 +176,4 @@
-
+
\ No newline at end of file
diff --git a/src/Workspaces/Core/Portable/HostBuild.cs b/src/Workspaces/Core/Portable/HostBuild.cs
new file mode 100644
index 0000000000000000000000000000000000000000..b85ca9bf7284743a52f200f3f18820782ee8813f
--- /dev/null
+++ b/src/Workspaces/Core/Portable/HostBuild.cs
@@ -0,0 +1,67 @@
+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 DelaySign { get; set; }
+ public List GlobalImports { get; set; }
+ public Dictionary Warnings { get; set; }
+
+ internal HostBuildOptions()
+ {
+ Warnings = new Dictionary();
+ GlobalImports = new List();
+ }
+ }
+
+ 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);
+ }
+}
diff --git a/src/Workspaces/Core/Desktop/Workspace/Host/CommandLineArgumentsFactory/ICommandLineArgumentsFactoryService.cs b/src/Workspaces/Core/Portable/Workspace/Host/CommandLineArgumentsFactory/ICommandLineArgumentsFactoryService.cs
similarity index 81%
rename from src/Workspaces/Core/Desktop/Workspace/Host/CommandLineArgumentsFactory/ICommandLineArgumentsFactoryService.cs
rename to src/Workspaces/Core/Portable/Workspace/Host/CommandLineArgumentsFactory/ICommandLineArgumentsFactoryService.cs
index f1f49cb8f4607bfe955d3a7b4ce2252c5f318936..adf93cb4a7b71c7a8ea9a666fcfc63b45d941504 100644
--- a/src/Workspaces/Core/Desktop/Workspace/Host/CommandLineArgumentsFactory/ICommandLineArgumentsFactoryService.cs
+++ b/src/Workspaces/Core/Portable/Workspace/Host/CommandLineArgumentsFactory/ICommandLineArgumentsFactoryService.cs
@@ -6,6 +6,6 @@ namespace Microsoft.CodeAnalysis.Host
{
internal interface ICommandLineArgumentsFactoryService : ILanguageService
{
- CommandLineArguments CreateCommandLineArguments(IEnumerable arguments, string baseDirectory, bool isInteractive);
+ CommandLineArguments CreateCommandLineArguments(IEnumerable arguments, string baseDirectory, bool isInteractive, string sdkDirectory);
}
}
diff --git a/src/Workspaces/Core/Portable/Workspaces.csproj b/src/Workspaces/Core/Portable/Workspaces.csproj
index 14407d6a2ca94c043ddaa92146210dc64c297ae0..7218079169264f770c19de1374192c4533739949 100644
--- a/src/Workspaces/Core/Portable/Workspaces.csproj
+++ b/src/Workspaces/Core/Portable/Workspaces.csproj
@@ -226,6 +226,24 @@
Serialization\SimpleRecordingObjectBinder.cs
+
+ InternalUtilities\FileUtilities.cs
+
+
+ InternalUtilities\PathUtilities.cs
+
+
+ InternalUtilities\AssemblyReferenceResolver.cs
+
+
+ InternalUtilities\MetadataFileReferenceResolver.cs
+
+
+ InternalUtilities\ReflectionUtil.cs
+
+
+ InternalUtilities\PortableShim.cs
+
@@ -384,6 +402,7 @@
+
@@ -548,6 +567,7 @@
+
diff --git a/src/Workspaces/VisualBasic/Desktop/BasicWorkspace.Desktop.vbproj b/src/Workspaces/VisualBasic/Desktop/BasicWorkspace.Desktop.vbproj
index e61ebe8ce309f473633a20278f0f950790233232..676362417260850231dbb87ca37ac7a1585ea920 100644
--- a/src/Workspaces/VisualBasic/Desktop/BasicWorkspace.Desktop.vbproj
+++ b/src/Workspaces/VisualBasic/Desktop/BasicWorkspace.Desktop.vbproj
@@ -52,10 +52,6 @@
{1EE8CAD3-55F9-4D91-96B2-084641DA9A6C}
CodeAnalysis
-
- {2523D0E6-DF32-4A3E-8AE0-A19BFFAE2EF6}
- BasicCodeAnalysis
-
{2e87fa96-50bb-4607-8676-46521599f998}
Workspaces.Desktop
@@ -72,11 +68,6 @@
-
-
-
-
-
@@ -88,4 +79,4 @@
-
+
\ No newline at end of file
diff --git a/src/Workspaces/VisualBasic/Desktop/LanguageServices/VisualBasicCommandLineArgumentsFactoryService.vb b/src/Workspaces/VisualBasic/Desktop/LanguageServices/VisualBasicCommandLineArgumentsFactoryService.vb
deleted file mode 100644
index 68ae9a54fd1073e9f1cdabae06fe5b940cf484ff..0000000000000000000000000000000000000000
--- a/src/Workspaces/VisualBasic/Desktop/LanguageServices/VisualBasicCommandLineArgumentsFactoryService.vb
+++ /dev/null
@@ -1,19 +0,0 @@
-' 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
-
- 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
diff --git a/src/Workspaces/VisualBasic/Desktop/MSBuild/VisualBasicProjectFileLoader.vb b/src/Workspaces/VisualBasic/Desktop/MSBuild/VisualBasicProjectFileLoader.vb
deleted file mode 100644
index 2343f50867617972595fbdc98b9363b267d9d035..0000000000000000000000000000000000000000
--- a/src/Workspaces/VisualBasic/Desktop/MSBuild/VisualBasicProjectFileLoader.vb
+++ /dev/null
@@ -1,794 +0,0 @@
-' 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.IO
-Imports System.Runtime.InteropServices
-Imports System.Threading
-Imports Microsoft.CodeAnalysis.Diagnostics
-Imports Microsoft.CodeAnalysis.Host
-Imports Microsoft.CodeAnalysis.MSBuild
-Imports Roslyn.Utilities
-Imports MSB = Microsoft.Build
-
-Namespace Microsoft.CodeAnalysis.VisualBasic
- Friend Class VisualBasicProjectFileLoader
- Inherits ProjectFileLoader
-
- Private ReadOnly _workspaceServices As HostWorkspaceServices
-
- Friend Sub New(workspaceServices As HostWorkspaceServices)
- Me._workspaceServices = workspaceServices
- End Sub
-
- Public Overrides ReadOnly Property Language As String
- Get
- Return LanguageNames.VisualBasic
- End Get
- End Property
-
- Protected Overrides Function CreateProjectFile(loadedProject As MSB.Evaluation.Project) As ProjectFile
- Return New VisualBasicProjectFile(Me, loadedProject, Me._workspaceServices.GetService(Of IMetadataService), Me._workspaceServices.GetService(Of IAnalyzerService))
- End Function
-
- Friend Class VisualBasicProjectFile
- Inherits ProjectFile
-
- Private ReadOnly _metadataService As IMetadataService
- Private ReadOnly _analyzerService As IAnalyzerService
-
- Public Sub New(loader As VisualBasicProjectFileLoader, loadedProject As MSB.Evaluation.Project, metadataService As IMetadataService, analyzerService As IAnalyzerService)
- MyBase.New(loader, loadedProject)
- Me._metadataService = metadataService
- Me._analyzerService = analyzerService
- End Sub
-
- Public Overrides Function GetSourceCodeKind(documentFileName As String) As SourceCodeKind
- If documentFileName.EndsWith(".vbx", StringComparison.OrdinalIgnoreCase) Then
- Return SourceCodeKind.Script
- End If
- Return SourceCodeKind.Regular
- End Function
-
- Public Overrides Function GetDocumentExtension(sourceCodeKind As SourceCodeKind) As String
- Select Case sourceCodeKind
- Case SourceCodeKind.Script
- Return ".vbx"
- Case Else
- Return ".vb"
- End Select
- End Function
-
- Public Overrides Async Function GetProjectFileInfoAsync(cancellationToken As CancellationToken) As Tasks.Task(Of ProjectFileInfo)
- Dim compilerInputs As New VisualBasicCompilerInputs(Me)
-
- Dim executedProject = Await Me.BuildAsync("Vbc", compilerInputs, cancellationToken).ConfigureAwait(False)
-
- If Not compilerInputs.Initialized Then
- Me.InitializeFromModel(compilerInputs, executedProject)
- End If
-
- Return CreateProjectFileInfo(compilerInputs, executedProject)
- End Function
-
- Private Shadows Function CreateProjectFileInfo(compilerInputs As VisualBasicCompilerInputs, executedProject As MSB.Execution.ProjectInstance) As ProjectFileInfo
-
- Dim metadataReferences As IEnumerable(Of MetadataReference) = Nothing
- Dim analyzerReferences As IEnumerable(Of AnalyzerReference) = Nothing
- GetReferences(compilerInputs, executedProject, metadataReferences, analyzerReferences)
-
- Dim outputPath = Path.Combine(Me.GetOutputDirectory(), compilerInputs.OutputFileName)
- Dim assemblyName = Me.GetAssemblyName()
-
- Return New ProjectFileInfo(
- outputPath,
- assemblyName,
- compilerInputs.CompilationOptions,
- compilerInputs.ParseOptions.WithPreprocessorSymbols(AddPredefinedPreprocessorSymbols(
- compilerInputs.CompilationOptions.OutputKind, compilerInputs.ParseOptions.PreprocessorSymbols)),
- compilerInputs.CodePage,
- Me.GetDocuments(compilerInputs.Sources, executedProject),
- Me.GetDocuments(compilerInputs.AdditionalFiles, executedProject),
- Me.GetProjectReferences(executedProject),
- metadataReferences,
- analyzerReferences)
- End Function
-
- Private Sub GetReferences(
- compilerInputs As VisualBasicCompilerInputs,
- executedProject As MSB.Execution.ProjectInstance,
- ByRef metadataReferences As IEnumerable(Of MetadataReference),
- ByRef analyzerReferences As IEnumerable(Of AnalyzerReference))
-
- ' use command line parser to compute references using common logic
-
- Dim args = New List(Of String)()
-
- If compilerInputs.LibPaths IsNot Nothing AndAlso compilerInputs.LibPaths.Count > 0 Then
- args.Add("/libpath:""" + String.Join(";", compilerInputs.LibPaths) + """")
- End If
-
- ' metadata references
- For Each mr In compilerInputs.References
- Dim filePath = GetDocumentFilePath(mr)
- args.Add("/r:""" + filePath + """")
- Next
-
- ' analyzer references
- For Each ar In compilerInputs.AnalyzerReferences
- Dim filePath = GetDocumentFilePath(ar)
- args.Add("/a:""" + filePath + """")
- Next
-
- If compilerInputs.NoStandardLib Then
- args.Add("/nostdlib")
- End If
-
- If Not String.IsNullOrEmpty(compilerInputs.VbRuntime) Then
- If compilerInputs.VbRuntime = "Default" Then
- args.Add("/vbruntime+")
- ElseIf compilerInputs.VbRuntime = "Embed" Then
- args.Add("/vbruntime*")
- ElseIf compilerInputs.VbRuntime = "None" Then 'TODO: check on this
- args.Add("/vbruntime-")
- Else
- args.Add("/vbruntime: " + compilerInputs.VbRuntime)
- End If
- End If
-
- If Not String.IsNullOrEmpty(compilerInputs.SdkPath) Then
- args.Add("/sdkpath:" + compilerInputs.SdkPath)
- End If
-
- Dim commandLineParser = VisualBasicCommandLineParser.Default
- Dim commandLineArgs = commandLineParser.Parse(args, executedProject.Directory, RuntimeEnvironment.GetRuntimeDirectory())
- Dim resolver = New MetadataFileReferenceResolver(commandLineArgs.ReferencePaths, commandLineArgs.BaseDirectory)
- metadataReferences = commandLineArgs.ResolveMetadataReferences(New AssemblyReferenceResolver(resolver, Me._metadataService.GetProvider()))
-
- Dim loader = _analyzerService.GetLoader()
- For Each path In commandLineArgs.AnalyzerReferences.Select(Function(r) r.FilePath)
- loader.AddDependencyLocation(path)
- Next
- analyzerReferences = commandLineArgs.ResolveAnalyzerReferences(loader)
-
- End Sub
-
- Private Function GetDocuments(sources As IEnumerable(Of Build.Framework.ITaskItem), executedProject As MSB.Execution.ProjectInstance) As IEnumerable(Of DocumentFileInfo)
- If sources Is Nothing Then
- Return ImmutableArray(Of DocumentFileInfo).Empty
- End If
-
- Dim projectDirectory = executedProject.Directory
- If Not projectDirectory.EndsWith(Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) Then
- projectDirectory += Path.DirectorySeparatorChar
- End If
-
- Return sources.Where(Function(s) Not System.IO.Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal)) _
- .Select(Function(s) New DocumentFileInfo(GetDocumentFilePath(s), GetDocumentLogicalPath(s, projectDirectory), IsDocumentLinked(s), IsDocumentGenerated(s))).ToImmutableArray()
- End Function
-
- Private Sub InitializeFromModel(compilerInputs As VisualBasicCompilerInputs, executedProject As MSB.Execution.ProjectInstance)
- compilerInputs.BeginInitialization()
-
- compilerInputs.SetBaseAddress(Me.ReadPropertyString(executedProject, "OutputType"), Me.ReadPropertyString(executedProject, "BaseAddress"))
- compilerInputs.SetCodePage(Me.ReadPropertyInt(executedProject, "CodePage"))
- compilerInputs.SetDebugType(Me.ReadPropertyBool(executedProject, "DebugSymbols"), Me.ReadPropertyString(executedProject, "DebugType"))
- compilerInputs.SetDefineConstants(Me.ReadPropertyString(executedProject, "FinalDefineConstants", "DefineConstants"))
- compilerInputs.SetDelaySign(Me.ReadPropertyBool(executedProject, "DelaySign"))
- compilerInputs.SetDisabledWarnings(Me.ReadPropertyString(executedProject, "NoWarn"))
- compilerInputs.SetDocumentationFile(Me.GetItemString(executedProject, "DocFileItem"))
- compilerInputs.SetErrorReport(Me.ReadPropertyString(executedProject, "ErrorReport"))
- compilerInputs.SetFileAlignment(Me.ReadPropertyInt(executedProject, "FileAlignment"))
- compilerInputs.SetGenerateDocumentation(Me.ReadPropertyBool(executedProject, "GenerateDocumentation"))
- compilerInputs.SetHighEntropyVA(Me.ReadPropertyBool(executedProject, "HighEntropyVA"))
-
- Dim _imports = Me.GetTaskItems(executedProject, "Import")
- If _imports IsNot Nothing Then
- compilerInputs.SetImports(_imports.ToArray())
- End If
-
- Dim signAssembly = ReadPropertyBool(executedProject, "SignAssembly")
- If signAssembly Then
- Dim keyFile = ReadPropertyString(executedProject, "KeyOriginatorFile", "AssemblyOriginatorKeyFile")
- If Not String.IsNullOrEmpty(keyFile) Then
- compilerInputs.SetKeyFile(keyFile)
- End If
-
- Dim keyContainer = ReadPropertyString(executedProject, "KeyContainerName")
- If Not String.IsNullOrEmpty(keyContainer) Then
- compilerInputs.SetKeyContainer(keyContainer)
- End If
- End If
-
- compilerInputs.SetLanguageVersion(Me.ReadPropertyString(executedProject, "LangVersion"))
- compilerInputs.SetMainEntryPoint(Me.ReadPropertyString(executedProject, "StartupObject"))
- compilerInputs.SetModuleAssemblyName(Me.ReadPropertyString(executedProject, "ModuleEntryPoint"))
- compilerInputs.SetNoStandardLib(Me.ReadPropertyBool(executedProject, "NoCompilerStandardLib", "NoStdLib"))
- compilerInputs.SetNoWarnings(Me.ReadPropertyBool(executedProject, "_NoWarnings"))
-
- compilerInputs.SetOptimize(Me.ReadPropertyBool(executedProject, "Optimize"))
- compilerInputs.SetOptionCompare(Me.ReadPropertyString(executedProject, "OptionCompare"))
- compilerInputs.SetOptionExplicit(Me.ReadPropertyBool(executedProject, "OptionExplicit"))
- compilerInputs.SetOptionInfer(Me.ReadPropertyBool(executedProject, "OptionInfer"))
-
- Dim optionStrictText = Me.ReadPropertyString(executedProject, "OptionStrict")
- Dim optionStrictValue As OptionStrict
- If TryGetOptionStrict(optionStrictText, optionStrictValue) Then
- compilerInputs.SetOptionStrict(optionStrictValue = OptionStrict.On)
- End If
-
- compilerInputs.SetOptionStrictType(Me.ReadPropertyString(executedProject, "OptionStrictType"))
-
- compilerInputs.SetOutputAssembly(Me.GetItemString(executedProject, "IntermediateAssembly"))
-
- If Me.ReadPropertyBool(executedProject, "Prefer32Bit") Then
- compilerInputs.SetPlatformWith32BitPreference(Me.ReadPropertyString(executedProject, "PlatformTarget"))
- Else
- compilerInputs.SetPlatform(Me.ReadPropertyString(executedProject, "PlatformTarget"))
- End If
-
- compilerInputs.SetRemoveIntegerChecks(Me.ReadPropertyBool(executedProject, "RemoveIntegerChecks"))
-
- compilerInputs.SetRootNamespace(Me.ReadPropertyString(executedProject, "RootNamespace"))
- compilerInputs.SetSdkPath(ReadPropertyString(executedProject, "FrameworkPathOverride"))
- compilerInputs.SetSubsystemVersion(Me.ReadPropertyString(executedProject, "SubsystemVersion"))
- compilerInputs.SetTargetCompactFramework(Me.ReadPropertyBool(executedProject, "TargetCompactFramework"))
- compilerInputs.SetTargetType(Me.ReadPropertyString(executedProject, "OutputType"))
-
- ' Decode the warning options from RuleSet file prior to reading explicit settings in the project file, so that project file settings prevail for duplicates.
- compilerInputs.SetRuleSet(Me.ReadPropertyString(executedProject, "RuleSet"))
- compilerInputs.SetTreatWarningsAsErrors(Me.ReadPropertyBool(executedProject, "SetTreatWarningsAsErrors"))
- compilerInputs.SetVBRuntime(ReadPropertyString(executedProject, "VbRuntime"))
- compilerInputs.SetWarningsAsErrors(Me.ReadPropertyString(executedProject, "WarningsAsErrors"))
- compilerInputs.SetWarningsNotAsErrors(Me.ReadPropertyString(executedProject, "WarningsNotAsErrors"))
-
- compilerInputs.SetReferences(Me.GetMetadataReferencesFromModel(executedProject).ToArray())
- compilerInputs.SetAnalyzers(Me.GetAnalyzerReferencesFromModel(executedProject).ToArray())
- compilerInputs.SetAdditionalFiles(Me.GetAdditionalFilesFromModel(executedProject).ToArray())
- compilerInputs.SetSources(Me.GetDocumentsFromModel(executedProject).ToArray())
-
- compilerInputs.EndInitialization()
- End Sub
-
- 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" Then
- optionStrictType = OptionStrict.Custom
- Return True
- Else
- Return False
- End If
- End Function
-
- Private Class VisualBasicCompilerInputs
- Implements MSB.Tasks.Hosting.IVbcHostObject5, MSB.Tasks.Hosting.IVbcHostObjectFreeThreaded
-#If Not MSBUILD12 Then
- Implements MSB.Tasks.Hosting.IAnalyzerHostObject
-#End If
- Private ReadOnly _projectFile As VisualBasicProjectFile
- Private _initialized As Boolean
- Private _parseOptions As VisualBasicParseOptions
- Private _compilationOptions As VisualBasicCompilationOptions
- Private _codePage As Integer
- Private _sources As IEnumerable(Of MSB.Framework.ITaskItem)
- Private _additionalFiles As IEnumerable(Of MSB.Framework.ITaskItem)
- Private _references As IEnumerable(Of MSB.Framework.ITaskItem)
- Private _analyzerReferences As IEnumerable(Of MSB.Framework.ITaskItem)
- Private _noStandardLib As Boolean
- Private ReadOnly _warnings As Dictionary(Of String, ReportDiagnostic)
- Private _sdkPath As String
- Private _targetCompactFramework As Boolean
- Private _vbRuntime As String
- Private _libPaths As IEnumerable(Of String)
- Private _outputFileName As String
-
- Public Sub New(projectFile As VisualBasicProjectFile)
- Me._projectFile = projectFile
- Me._parseOptions = VisualBasicParseOptions.Default.WithDocumentationMode(DocumentationMode.Parse)
- Dim projectDirectory = Path.GetDirectoryName(projectFile.FilePath)
- Dim outputDirectory = projectFile.GetOutputDirectory()
- Me._compilationOptions = New VisualBasicCompilationOptions(OutputKind.ConsoleApplication,
- xmlReferenceResolver:=New XmlFileResolver(projectDirectory),
- sourceReferenceResolver:=New SourceFileResolver(ImmutableArray(Of String).Empty, projectDirectory),
- metadataReferenceResolver:=New AssemblyReferenceResolver(
- New MetadataFileReferenceResolver(ImmutableArray(Of String).Empty, projectDirectory),
- MetadataFileReferenceProvider.Default),
- strongNameProvider:=New DesktopStrongNameProvider(ImmutableArray.Create(Of String)(projectDirectory, outputDirectory)),
- assemblyIdentityComparer:=DesktopAssemblyIdentityComparer.Default)
- Me._sources = SpecializedCollections.EmptyEnumerable(Of MSB.Framework.ITaskItem)()
- Me._references = SpecializedCollections.EmptyEnumerable(Of MSB.Framework.ITaskItem)()
- Me._analyzerReferences = SpecializedCollections.EmptyEnumerable(Of MSB.Framework.ITaskItem)()
- Me._warnings = New Dictionary(Of String, ReportDiagnostic)()
- End Sub
-
- Public ReadOnly Property Initialized As Boolean
- Get
- Return Me._initialized
- End Get
- End Property
-
- Public ReadOnly Property CompilationOptions As VisualBasicCompilationOptions
- Get
- Return Me._compilationOptions
- End Get
- End Property
-
- Public ReadOnly Property ParseOptions As VisualBasicParseOptions
- Get
- Return Me._parseOptions
- End Get
- End Property
-
- Public ReadOnly Property CodePage As Integer
- Get
- Return Me._codePage
- End Get
- End Property
-
- Public ReadOnly Property References As IEnumerable(Of MSB.Framework.ITaskItem)
- Get
- Return Me._references
- End Get
- End Property
-
- Public ReadOnly Property AnalyzerReferences As IEnumerable(Of MSB.Framework.ITaskItem)
- Get
- Return Me._analyzerReferences
- End Get
- End Property
-
- Public ReadOnly Property Sources As IEnumerable(Of MSB.Framework.ITaskItem)
- Get
- Return Me._sources
- End Get
- End Property
-
- Public ReadOnly Property AdditionalFiles As IEnumerable(Of MSB.Framework.ITaskItem)
- Get
- Return Me._additionalFiles
- End Get
- End Property
-
- Public ReadOnly Property NoStandardLib As Boolean
- Get
- Return Me._noStandardLib
- End Get
- End Property
-
- Public ReadOnly Property VbRuntime As String
- Get
- Return Me._vbRuntime
- End Get
- End Property
-
- Public ReadOnly Property SdkPath As String
- Get
- Return Me._sdkPath
- End Get
- End Property
-
- Public ReadOnly Property TargetCompactFramework As Boolean
- Get
- Return Me._targetCompactFramework
- End Get
- End Property
-
- Public ReadOnly Property LibPaths As IEnumerable(Of String)
- Get
- Return Me._libPaths
- End Get
- End Property
-
- Public ReadOnly Property OutputFileName As String
- Get
- Return Me._outputFileName
- End Get
- End Property
-
- Public Sub BeginInitialization() Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.BeginInitialization
- End Sub
-
- Public Function Compile() As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.Compile
- Return False
- End Function
-
- Public Sub EndInitialization() Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.EndInitialization
- If Me._warnings.Count > 0 Then
- Me._compilationOptions = Me._compilationOptions.WithSpecificDiagnosticOptions(Me._warnings)
- End If
-
- Me._initialized = True
- End Sub
-
- Public Function IsDesignTime() As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.IsDesignTime
- Return True
- End Function
-
- Public Function IsUpToDate() As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.IsUpToDate
- Return True
- End Function
-
- Public Function SetAdditionalLibPaths(additionalLibPaths() As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetAdditionalLibPaths
- Me._libPaths = additionalLibPaths
- Return True
- End Function
-
- Public Function SetAddModules(addModules() As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetAddModules
- Return True
- End Function
-
- Public Function SetBaseAddress(targetType As String, baseAddress As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetBaseAddress
- ' we don't capture emit options
- Return True
- End Function
-
- Public Function SetCodePage(codePage As Integer) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetCodePage
- Me._codePage = codePage
- Return True
- End Function
-
- Public Function SetDebugType(emitDebugInformation As Boolean, debugType As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetDebugType
- ' ignore, just check for expected values for backwards compat
- Return String.Equals(debugType, "none", StringComparison.OrdinalIgnoreCase) OrElse
- String.Equals(debugType, "pdbonly", StringComparison.OrdinalIgnoreCase) OrElse
- String.Equals(debugType, "full", StringComparison.OrdinalIgnoreCase)
- End Function
-
- Public Function SetDefineConstants(defineConstants As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetDefineConstants
- If Not String.IsNullOrEmpty(defineConstants) Then
- Dim errors As IEnumerable(Of Diagnostic) = Nothing
- Me._parseOptions = Me._parseOptions.WithPreprocessorSymbols(VisualBasicCommandLineParser.ParseConditionalCompilationSymbols(defineConstants, errors))
- Return True
- End If
- Return False
- End Function
-
- Public Function SetDelaySign(delaySign As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetDelaySign
- Me._compilationOptions = Me._compilationOptions.WithDelaySign(delaySign)
- Return True
- End Function
-
- Public Function SetDisabledWarnings(disabledWarnings As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetDisabledWarnings
- SetWarnings(disabledWarnings, ReportDiagnostic.Suppress)
- Return True
- End Function
-
- Public Function SetDocumentationFile(documentationFile As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetDocumentationFile
- If Not String.IsNullOrEmpty(documentationFile) Then
- _parseOptions = _parseOptions.WithDocumentationMode(DocumentationMode.Diagnose)
- Else
- _parseOptions = _parseOptions.WithDocumentationMode(DocumentationMode.Parse)
- End If
-
- Return True
- End Function
-
- Public Function SetErrorReport(errorReport As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetErrorReport
- ' ??
- Return True
- End Function
-
- Public Function SetFileAlignment(fileAlignment As Integer) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetFileAlignment
- ' we don't capture emit options
- Return True
- End Function
-
- Public Function SetGenerateDocumentation(generateDocumentation As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetGenerateDocumentation
- Return True
- End Function
-
- Public Function SetImports(importsList() As Microsoft.Build.Framework.ITaskItem) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetImports
- If importsList IsNot Nothing Then
- Dim array = importsList.Select(Function(item) GlobalImport.Parse(item.ItemSpec.Trim()))
- Me._compilationOptions = Me._compilationOptions.WithGlobalImports(array)
- End If
- Return True
- End Function
-
- Public Function SetKeyContainer(keyContainer As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetKeyContainer
- If Not String.IsNullOrEmpty(keyContainer) Then
- Me._compilationOptions = Me._compilationOptions.WithCryptoKeyContainer(keyContainer)
- Return True
- End If
- Return False
- End Function
-
- Public Function SetKeyFile(keyFile As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetKeyFile
- If Not String.IsNullOrEmpty(keyFile) Then
- Me._compilationOptions = Me._compilationOptions.WithCryptoKeyFile(keyFile)
- Return True
- End If
- Return False
- End Function
-
- Public Function SetLinkResources(linkResources() As Microsoft.Build.Framework.ITaskItem) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetLinkResources
- ' ??
- Return True
- End Function
-
- Public Function SetMainEntryPoint(mainEntryPoint As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetMainEntryPoint
- If Not String.IsNullOrEmpty(mainEntryPoint) AndAlso mainEntryPoint <> "Sub Main" Then
- Me._compilationOptions = Me._compilationOptions.WithMainTypeName(mainEntryPoint)
- End If
- Return True
- End Function
-
- Public Function SetNoConfig(noConfig As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetNoConfig
- Return True
- End Function
-
- Public Function SetNoStandardLib(noStandardLib As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetNoStandardLib
- Me._noStandardLib = noStandardLib
- Return True
- End Function
-
- Public Function SetNoWarnings(noWarnings As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetNoWarnings
- Me._compilationOptions = Me._compilationOptions.WithGeneralDiagnosticOption(If(noWarnings, ReportDiagnostic.Suppress, ReportDiagnostic.Warn))
- Return True
- End Function
-
- Public Function SetOptimize(optimize As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetOptimize
- Me._compilationOptions = Me._compilationOptions.WithOptimizationLevel(If(optimize, OptimizationLevel.Release, OptimizationLevel.Debug))
- Return True
- End Function
-
- Public Function SetOptionCompare(optionCompare As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetOptionCompare
- If Not String.IsNullOrEmpty(optionCompare) Then
- Me._compilationOptions = Me._compilationOptions.WithOptionCompareText(optionCompare = "Text")
- Return True
- End If
- Return False
- End Function
-
- Public Function SetOptionExplicit(optionExplicit As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetOptionExplicit
- Me._compilationOptions = Me._compilationOptions.WithOptionExplicit(optionExplicit)
- Return True
- End Function
-
- Public Function SetOptionStrict(_optionStrict As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetOptionStrict
- Me._compilationOptions = Me._compilationOptions.WithOptionStrict(If(_optionStrict, OptionStrict.On, OptionStrict.Custom))
- Return True
- End Function
-
- Public Function SetOptionStrictType(optionStrictType As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetOptionStrictType
- If Not String.IsNullOrEmpty(optionStrictType) Then
- Dim _optionStrict As OptionStrict = OptionStrict.Custom
- If VisualBasicProjectFile.TryGetOptionStrict(optionStrictType, _optionStrict) Then
- Me._compilationOptions = Me._compilationOptions.WithOptionStrict(_optionStrict)
- Return True
- End If
- End If
- Return False
- End Function
-
- Public Function SetOutputAssembly(outputAssembly As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetOutputAssembly
- Me._outputFileName = Path.GetFileName(outputAssembly)
- Return True
- End Function
-
- Public Function SetPlatform(_platform As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetPlatform
- If Not String.IsNullOrEmpty(_platform) Then
- Dim plat As Platform
- If [Enum].TryParse(_platform, plat) Then
- Me._compilationOptions = Me._compilationOptions.WithPlatform(plat)
- Return True
- End If
- End If
- Return False
- End Function
-
- Public Function SetPlatformWith32BitPreference(_platform As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject5.SetPlatformWith32BitPreference
- If Not String.IsNullOrEmpty(_platform) Then
- Dim plat As Platform
- If [Enum].TryParse(_platform, True, plat) Then
- Dim outputKind = Me._compilationOptions.OutputKind
- If plat = Platform.AnyCpu AndAlso outputKind <> OutputKind.DynamicallyLinkedLibrary AndAlso outputKind <> OutputKind.NetModule AndAlso outputKind <> OutputKind.WindowsRuntimeMetadata Then
- plat = Platform.AnyCpu32BitPreferred
- End If
- Me._compilationOptions = Me._compilationOptions.WithPlatform(plat)
- Return True
- End If
- End If
- Return False
- End Function
-
- Public Function SetReferences(references() As Microsoft.Build.Framework.ITaskItem) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetReferences
- Me._references = If(references, SpecializedCollections.EmptyEnumerable(Of MSB.Framework.ITaskItem)())
- Return True
- End Function
-
-#If Not MSBUILD12 Then
- Public Function SetAnalyzers(analyzerReferences() As MSB.Framework.ITaskItem) As Boolean Implements MSB.Tasks.Hosting.IAnalyzerHostObject.SetAnalyzers
-#Else
- Public Function SetAnalyzers(analyzerReferences() As MSB.Framework.ITaskItem) As Boolean
-#End If
- Me._analyzerReferences = If(analyzerReferences, SpecializedCollections.EmptyEnumerable(Of MSB.Framework.ITaskItem)())
- Return True
- End Function
-
-#If Not MSBUILD12 Then
- Public Function SetAdditionalFiles(additionalFiles() As MSB.Framework.ITaskItem) As Boolean Implements MSB.Tasks.Hosting.IAnalyzerHostObject.SetAdditionalFiles
-#Else
- Public Function SetAdditionalFiles(additionalFiles() As MSB.Framework.ITaskItem) As Boolean
-#End If
- Me._additionalFiles = If(additionalFiles, SpecializedCollections.EmptyEnumerable(Of MSB.Framework.ITaskItem)())
- Return True
- End Function
-
- Public Function SetRemoveIntegerChecks(removeIntegerChecks As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetRemoveIntegerChecks
- Me._compilationOptions = Me._compilationOptions.WithOverflowChecks(Not removeIntegerChecks)
- Return True
- End Function
-
- Public Function SetResources(resources() As Microsoft.Build.Framework.ITaskItem) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetResources
- Return True
- End Function
-
- Public Function SetResponseFiles(responseFiles() As Microsoft.Build.Framework.ITaskItem) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetResponseFiles
- Return True
- End Function
-
- Public Function SetRootNamespace(rootNamespace As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetRootNamespace
- If Not String.IsNullOrEmpty(rootNamespace) Then
- Me._compilationOptions = Me._compilationOptions.WithRootNamespace(rootNamespace)
- Return True
- End If
- Return False
- End Function
-
- Public Function SetSdkPath(sdkPath As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetSdkPath
- Me._sdkPath = sdkPath
- Return True
- End Function
-
- Public Function SetSources(sources() As Microsoft.Build.Framework.ITaskItem) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetSources
- Me._sources = If(sources, SpecializedCollections.EmptyEnumerable(Of MSB.Framework.ITaskItem)())
- Return True
- End Function
-
- Public Function SetTargetCompactFramework(targetCompactFramework As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetTargetCompactFramework
- Me._targetCompactFramework = targetCompactFramework
- Return True
- End Function
-
- Public Function SetTargetType(targetType As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetTargetType
- If Not String.IsNullOrEmpty(targetType) Then
- Dim _outputKind As OutputKind
- If VisualBasicProjectFile.TryGetOutputKind(targetType, _outputKind) Then
- Me._compilationOptions = Me._compilationOptions.WithOutputKind(_outputKind)
- If Me._compilationOptions.Platform = Platform.AnyCpu32BitPreferred AndAlso
- (_outputKind = OutputKind.DynamicallyLinkedLibrary Or _outputKind = OutputKind.NetModule Or _outputKind = OutputKind.WindowsRuntimeMetadata) Then
- Me._compilationOptions = Me._compilationOptions.WithPlatform(Platform.AnyCpu)
- End If
- Return True
- End If
- End If
- Return False
- End Function
-
-#If Not MSBUILD12 Then
- Public Function SetRuleSet(ruleSetFile As String) As Boolean Implements MSB.Tasks.Hosting.IAnalyzerHostObject.SetRuleSet
-#Else
- Public Function SetRuleSet(ruleSetFile As String) As Boolean
-#End If
- If Not String.IsNullOrEmpty(ruleSetFile) Then
- Dim fullPath = FileUtilities.ResolveRelativePath(ruleSetFile, Path.GetDirectoryName(Me._projectFile.FilePath))
-
- Dim specificDiagnosticOptions As Dictionary(Of String, ReportDiagnostic) = Nothing
- Dim generalDiagnosticOption = RuleSet.GetDiagnosticOptionsFromRulesetFile(fullPath, specificDiagnosticOptions)
- Me._compilationOptions = Me._compilationOptions.WithGeneralDiagnosticOption(generalDiagnosticOption)
- Me._warnings.AddRange(specificDiagnosticOptions)
- End If
-
- Return True
- End Function
-
- Public Function SetTreatWarningsAsErrors(treatWarningsAsErrors As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetTreatWarningsAsErrors
- Me._compilationOptions = Me._compilationOptions.WithGeneralDiagnosticOption(If(treatWarningsAsErrors, ReportDiagnostic.Error, ReportDiagnostic.Warn))
- Return True
- End Function
-
- Public Function SetWarningsAsErrors(warningsAsErrors As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetWarningsAsErrors
- SetWarnings(warningsAsErrors, ReportDiagnostic.Error)
- Return True
- End Function
-
- Private Shared ReadOnly s_warningSeparators As Char() = {";"c, ","c}
-
- Private Sub SetWarnings(warnings As String, reportStyle As ReportDiagnostic)
- If Not String.IsNullOrEmpty(warnings) Then
- For Each warning In warnings.Split(s_warningSeparators, StringSplitOptions.None)
- Dim warningId As Integer
- If Int32.TryParse(warning, warningId) Then
- Me._warnings("BC" + warningId.ToString("0000")) = reportStyle
- Else
- Me._warnings(warning) = reportStyle
- End If
- Next
- End If
- End Sub
-
- Public Function SetWarningsNotAsErrors(warningsNotAsErrors As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetWarningsNotAsErrors
- SetWarnings(warningsNotAsErrors, ReportDiagnostic.Warn)
- Return True
- End Function
-
- Public Function SetWin32Icon(win32Icon As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetWin32Icon
- Return True
- End Function
-
- Public Function SetWin32Resource(win32Resource As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject.SetWin32Resource
- Return True
- End Function
-
- Public Function SetModuleAssemblyName(moduleAssemblyName As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject2.SetModuleAssemblyName
- Return True
- End Function
-
- Public Function SetOptionInfer(optionInfer As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject2.SetOptionInfer
- Me._compilationOptions = Me._compilationOptions.WithOptionInfer(optionInfer)
- Return True
- End Function
-
- Public Function SetWin32Manifest(win32Manifest As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject2.SetWin32Manifest
- Return True
- End Function
-
- Public Function SetLanguageVersion(_languageVersion As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject3.SetLanguageVersion
- If Not String.IsNullOrEmpty(_languageVersion) Then
- Dim version As Integer
- If Int32.TryParse(_languageVersion, version) Then
- Dim lv As LanguageVersion = CType(version, LanguageVersion)
- If [Enum].IsDefined(GetType(LanguageVersion), lv) Then
- Me._parseOptions = Me._parseOptions.WithLanguageVersion(lv)
- Return True
- End If
- End If
- End If
- Return False
- End Function
-
- Public Function SetVBRuntime(VBRuntime As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject4.SetVBRuntime
- Me._vbRuntime = VBRuntime
-
- If VBRuntime = "Embed" Then
- Me._compilationOptions = Me._compilationOptions.WithEmbedVbCoreRuntime(True)
- End If
-
- Return True
- End Function
-
- Public Function CompileAsync(ByRef buildSucceededEvent As IntPtr, ByRef buildFailedEvent As IntPtr) As Integer Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject5.CompileAsync
- Return 0
- End Function
-
- Public Function EndCompile(buildSuccess As Boolean) As Integer Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject5.EndCompile
- Return 0
- End Function
-
- Public Function GetFreeThreadedHostObject() As Microsoft.Build.Tasks.Hosting.IVbcHostObjectFreeThreaded Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject5.GetFreeThreadedHostObject
- Return Nothing
- End Function
-
- Public Function SetHighEntropyVA(highEntropyVA As Boolean) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject5.SetHighEntropyVA
- ' we don't capture emit options
- Return True
- End Function
-
- Public Function SetSubsystemVersion(subsystemVersion As String) As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObject5.SetSubsystemVersion
- ' we don't capture emit options
- Return True
- End Function
-
- Public Function Compile1() As Boolean Implements Microsoft.Build.Tasks.Hosting.IVbcHostObjectFreeThreaded.Compile
- Return False
- End Function
-
- End Class
-
- End Class
-
- End Class
-
-End Namespace
diff --git a/src/Workspaces/VisualBasic/Desktop/MSBuild/VisualBasicProjectFileLoaderFactory.vb b/src/Workspaces/VisualBasic/Desktop/MSBuild/VisualBasicProjectFileLoaderFactory.vb
deleted file mode 100644
index c59529d1a2083542a7096b2c76172e1fcab63760..0000000000000000000000000000000000000000
--- a/src/Workspaces/VisualBasic/Desktop/MSBuild/VisualBasicProjectFileLoaderFactory.vb
+++ /dev/null
@@ -1,20 +0,0 @@
-' 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
-
-
-
- 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
-
diff --git a/src/Workspaces/VisualBasic/Portable/BasicWorkspace.vbproj b/src/Workspaces/VisualBasic/Portable/BasicWorkspace.vbproj
index fe665df5b7852e65fbde96403eefd655d54883c7..6ff9c26e2fed3b26fda2302a43ad7e346e861de4 100644
--- a/src/Workspaces/VisualBasic/Portable/BasicWorkspace.vbproj
+++ b/src/Workspaces/VisualBasic/Portable/BasicWorkspace.vbproj
@@ -203,6 +203,7 @@
+
diff --git a/src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicHostBuildDataFactory.vb b/src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicHostBuildDataFactory.vb
new file mode 100644
index 0000000000000000000000000000000000000000..f26deece51861becd1577116f77e01ea4fbd9252
--- /dev/null
+++ b/src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicHostBuildDataFactory.vb
@@ -0,0 +1,188 @@
+' 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
+
+
+ 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
+
+
+
+ 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
+