Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rebuild.UnitTests #51778

Merged
merged 17 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Compilers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.CodeAnalysis.Coll
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rebuild", "src\Compilers\Core\Rebuild\Rebuild.csproj", "{321F9FED-AACC-42CB-93E5-541D79E099E8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Rebuild.UnitTests", "src\Compilers\Core\RebuildTest\Microsoft.CodeAnalysis.Rebuild.UnitTests.csproj", "{FDBFBB64-5980-41C2-9E3E-FB8E2F700A5C}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Analyzers\VisualBasic\CodeFixes\VisualBasicCodeFixes.projitems*{0141285d-8f6c-42c7-baf3-3c0ccd61c716}*SharedItemsImports = 5
Expand Down Expand Up @@ -473,6 +475,10 @@ Global
{321F9FED-AACC-42CB-93E5-541D79E099E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{321F9FED-AACC-42CB-93E5-541D79E099E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{321F9FED-AACC-42CB-93E5-541D79E099E8}.Release|Any CPU.Build.0 = Release|Any CPU
{FDBFBB64-5980-41C2-9E3E-FB8E2F700A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDBFBB64-5980-41C2-9E3E-FB8E2F700A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDBFBB64-5980-41C2-9E3E-FB8E2F700A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDBFBB64-5980-41C2-9E3E-FB8E2F700A5C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -549,6 +555,7 @@ Global
{432F4461-E198-44AA-8022-9E8C06A17C93} = {B20208C3-D3A6-4020-A274-6BE3786D29FB}
{E919DD77-34F8-4F57-8058-4D3FF4C2B241} = {3CDEA9FB-CD44-4AB4-98A8-5537AAA2169B}
{321F9FED-AACC-42CB-93E5-541D79E099E8} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9}
{FDBFBB64-5980-41C2-9E3E-FB8E2F700A5C} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6F599E08-A9EA-4FAA-897F-5D824B0210E6}
Expand Down
1 change: 1 addition & 0 deletions Compilers.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"src\\Compilers\\Core\\MSBuildTaskTests\\Microsoft.Build.Tasks.CodeAnalysis.UnitTests.csproj",
"src\\Compilers\\Core\\MSBuildTask\\Microsoft.Build.Tasks.CodeAnalysis.csproj",
"src\\Compilers\\Core\\Portable\\Microsoft.CodeAnalysis.csproj",
"src\\Compilers\\Core\\RebuildTest\\Microsoft.CodeAnalysis.Rebuild.UnitTests.csproj",
"src\\Compilers\\Core\\Rebuild\\Rebuild.csproj",
"src\\Compilers\\Extension\\Roslyn.Compilers.Extension.csproj",
"src\\Compilers\\Server\\VBCSCompilerTests\\VBCSCompiler.UnitTests.csproj",
Expand Down
7 changes: 7 additions & 0 deletions Roslyn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Coll
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rebuild", "src\Compilers\Core\Rebuild\Rebuild.csproj", "{B7D29559-4360-434A-B9B9-2C0612287999}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Rebuild.UnitTests", "src\Compilers\Core\RebuildTest\Microsoft.CodeAnalysis.Rebuild.UnitTests.csproj", "{21B49277-E55A-45EF-8818-744BCD6CB732}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Analyzers\VisualBasic\CodeFixes\VisualBasicCodeFixes.projitems*{0141285d-8f6c-42c7-baf3-3c0ccd61c716}*SharedItemsImports = 5
Expand Down Expand Up @@ -1266,6 +1268,10 @@ Global
{B7D29559-4360-434A-B9B9-2C0612287999}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7D29559-4360-434A-B9B9-2C0612287999}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7D29559-4360-434A-B9B9-2C0612287999}.Release|Any CPU.Build.0 = Release|Any CPU
{21B49277-E55A-45EF-8818-744BCD6CB732}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21B49277-E55A-45EF-8818-744BCD6CB732}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21B49277-E55A-45EF-8818-744BCD6CB732}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21B49277-E55A-45EF-8818-744BCD6CB732}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1488,6 +1494,7 @@ Global
{E919DD77-34F8-4F57-8058-4D3FF4C2B241} = {C2D1346B-9665-4150-B644-075CF1636BAA}
{0C2E1633-1462-4712-88F4-A0C945BAD3A8} = {C2D1346B-9665-4150-B644-075CF1636BAA}
{B7D29559-4360-434A-B9B9-2C0612287999} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9}
{21B49277-E55A-45EF-8818-744BCD6CB732} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {604E6B91-7BC0-4126-AE07-D4D2FEFC3D29}
Expand Down
3 changes: 3 additions & 0 deletions eng/test-rebuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ try {
" --exclude net472\Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests.dll" +
" --exclude netcoreapp3.1\Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests.dll" +
" --exclude net472\Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll" +
" --exclude net472\Microsoft.CodeAnalysis.EditorFeatures2.UnitTests.dll" +
" --exclude net472\Microsoft.CodeAnalysis.ExpressionEvaluator.FunctionResolver.UnitTests.dll" +
" --exclude net472\Microsoft.CodeAnalysis.ExternalAccess.FSharp.UnitTests.dll" +
" --exclude netcoreapp3.1\Microsoft.CodeAnalysis.Features.dll" +
" --exclude netstandard2.0\Microsoft.CodeAnalysis.Features.dll" +
" --exclude net472\Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests.dll" +
" --exclude net5.0\Microsoft.CodeAnalysis.Rebuild.UnitTests.dll" +
" --exclude net472\Microsoft.CodeAnalysis.Rebuild.UnitTests.dll" +
" --exclude net472\Microsoft.CodeAnalysis.Scripting.Desktop.UnitTests.dll" +
" --exclude net472\Microsoft.CodeAnalysis.UnitTests.dll" +
" --exclude net5.0\Microsoft.CodeAnalysis.UnitTests.dll" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal static class CompilationOptionNames
public const string DefaultEncoding = "default-encoding";
public const string PortabilityPolicy = "portability-policy";
public const string RuntimeVersion = "runtime-version";
public const string Platform = "platform";
public const string Optimization = "optimization";
public const string Checked = "checked";
public const string Language = "language";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,9 @@ private void EmbedCompilationOptions(BlobReader? pdbCompilationOptionsReader, Co
WriteValue(CompilationOptionNames.Optimization, optimizationLevel.ToPdbSerializedString(debugPlusMode));
}

var platform = module.CommonCompilation.Options.Platform;
WriteValue(CompilationOptionNames.Platform, platform.ToString());
Copy link
Member

@tmat tmat Mar 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Platform can't be determined from the CLR/PE header flags of the dll? Seems like it should be possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be possible, but I wasn't able to get all the values to round trip. The CoffHeader.Machine, for example, is not enough information. There must be other bits that imply Platform.AnyCpu and Platform.AnyCpu32BitPreferred that I just wasn't able to find.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #51941 to make sure we get to this. Thanks


var runtimeVersion = typeof(object).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
WriteValue(CompilationOptionNames.RuntimeVersion, runtimeVersion);

Expand Down
23 changes: 15 additions & 8 deletions src/Compilers/Core/Rebuild/BuildConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,16 @@ private Compilation CreateCSharpCompilation(
using var scope = _logger.BeginScope("Options");
var pdbCompilationOptions = optionsReader.GetMetadataCompilationOptions();

var langVersionString = pdbCompilationOptions.GetUniqueOption("language-version");
var optimization = pdbCompilationOptions.GetUniqueOption("optimization");
var langVersionString = pdbCompilationOptions.GetUniqueOption(CompilationOptionNames.LanguageVersion);
pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.Optimization, out var optimization);
pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.Platform, out var platform);

// TODO: Check portability policy if needed
// pdbCompilationOptions.TryGetValue("portability-policy", out var portabilityPolicyString);
pdbCompilationOptions.TryGetUniqueOption(_logger, "define", out var define);
pdbCompilationOptions.TryGetUniqueOption(_logger, "checked", out var checkedString);
pdbCompilationOptions.TryGetUniqueOption(_logger, "nullable", out var nullable);
pdbCompilationOptions.TryGetUniqueOption(_logger, "unsafe", out var unsafeString);
pdbCompilationOptions.TryGetUniqueOption(_logger, CompilationOptionNames.Define, out var define);
pdbCompilationOptions.TryGetUniqueOption(_logger, CompilationOptionNames.Checked, out var checkedString);
pdbCompilationOptions.TryGetUniqueOption(_logger, CompilationOptionNames.Nullable, out var nullable);
pdbCompilationOptions.TryGetUniqueOption(_logger, CompilationOptionNames.Unsafe, out var unsafeString);

CS.LanguageVersionFacts.TryParse(langVersionString, out var langVersion);

Expand Down Expand Up @@ -142,7 +143,7 @@ private Compilation CreateCSharpCompilation(
cryptoKeyFile: null,
cryptoPublicKey: optionsReader.GetPublicKey()?.ToImmutableArray() ?? default,
delaySign: null,
Platform.AnyCpu,
GetPlatform(platform),

// presence of diagnostics is expected to not affect emit.
ReportDiagnostic.Suppress,
Expand Down Expand Up @@ -176,6 +177,11 @@ private static (OptimizationLevel, bool) GetOptimizationLevel(string? optimizati
_ => throw new InvalidDataException($"Optimization \"{optimizationLevel}\" level not recognized")
};

private static Platform GetPlatform(string? platform)
jaredpar marked this conversation as resolved.
Show resolved Hide resolved
=> platform is null
? Platform.AnyCpu
: (Platform)Enum.Parse(typeof(Platform), platform);

private Compilation CreateVisualBasicCompilation(
string fileName,
CompilationOptionsReader optionsReader,
Expand All @@ -197,6 +203,7 @@ private static VisualBasicCompilationOptions CreateVisualBasicCompilationOptions

var langVersionString = pdbCompilationOptions.GetUniqueOption(CompilationOptionNames.LanguageVersion);
pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.Optimization, out var optimization);
pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.Platform, out var platform);
pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.GlobalNamespaces, out var globalNamespacesString);

IEnumerable<GlobalImport>? globalImports = null;
Expand Down Expand Up @@ -247,7 +254,7 @@ private static VisualBasicCompilationOptions CreateVisualBasicCompilationOptions
cryptoKeyFile: null,
cryptoPublicKey: optionsReader.GetPublicKey()?.ToImmutableArray() ?? default,
delaySign: null,
platform: Platform.AnyCpu,
platform: GetPlatform(platform),
generalDiagnosticOption: ReportDiagnostic.Default,
specificDiagnosticOptions: null,
concurrentBuild: true,
Expand Down
5 changes: 3 additions & 2 deletions src/Compilers/Core/Rebuild/CompilationOptionsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.Logging;
using Roslyn.Utilities;

namespace BuildValidator
{
Expand Down Expand Up @@ -95,8 +96,8 @@ public Encoding GetEncoding()
using var scope = _logger.BeginScope("Encoding");

var optionsReader = GetMetadataCompilationOptions();
optionsReader.TryGetUniqueOption(_logger, "default-encoding", out var defaultEncoding);
optionsReader.TryGetUniqueOption(_logger, "fallback-encoding", out var fallbackEncoding);
optionsReader.TryGetUniqueOption(_logger, CompilationOptionNames.DefaultEncoding, out var defaultEncoding);
optionsReader.TryGetUniqueOption(_logger, CompilationOptionNames.FallbackEncoding, out var fallbackEncoding);

var encodingString = defaultEncoding ?? fallbackEncoding;
var encoding = encodingString is null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.Rebuild.UnitTests</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>net5.0;net472</TargetFrameworks>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
<ProjectReference Include="..\..\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
<ProjectReference Include="..\..\Test\Core\Microsoft.CodeAnalysis.Test.Utilities.csproj" />
<ProjectReference Include="..\..\Test\Resources\Core\Microsoft.CodeAnalysis.Compiler.Test.Resources.csproj" />
<ProjectReference Include="..\..\Test\Utilities\CSharp\Microsoft.CodeAnalysis.CSharp.Test.Utilities.csproj" />
<ProjectReference Include="..\Rebuild\Rebuild.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
</Project>
126 changes: 126 additions & 0 deletions src/Compilers/Core/RebuildTest/OptionRoundTripTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System;
using System.Reflection.PortableExecutable;
using BuildValidator;
using Castle.Core.Logging;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.Extensions.Logging;
using Xunit;
using System.IO;
using System.Threading;
using Microsoft.CodeAnalysis.VisualBasic;
using System.Text;

namespace Microsoft.CodeAnalysis.Rebuild.UnitTests
{
public class OptionRoundTripTests : CSharpTestBase
{
public static readonly object[][] s_platforms = ((Platform[])Enum.GetValues(typeof(Platform))).Select(p => new[] { (object)p }).ToArray();

[Theory]
[MemberData(nameof(s_platforms))]
public void Platform_RoundTrip(Platform platform)
{
const string path = "test";

var original = CreateCompilation(
"class C { static void Main() { } }",
options: TestOptions.DebugExe.WithPlatform(platform));

original.VerifyDiagnostics();

var originalBytes = original.EmitToArray(new EmitOptions(debugInformationFormat: DebugInformationFormat.Embedded));
var peReader = new PEReader(originalBytes);
Assert.True(peReader.TryOpenAssociatedPortablePdb(path, path => null, out var provider, out _));
var pdbReader = provider!.GetMetadataReader();

var factory = LoggerFactory.Create(configure => { });
var logger = factory.CreateLogger(path);
// TODO: shouldn't need to pass a logger.
Copy link
Member

@cston cston Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need an ILogger instance, could we create a simple implementation of ILogger in this test class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it feels like users of the public API shouldn't be required to provide a logger, and shouldn't provide it as its own parameter. Maybe a property on an options object that can be specified if the user wants, but not a parameter to public API that they have to deal with.

var bc = new BuildConstructor(logger);

var optionsReader = new CompilationOptionsReader(logger, pdbReader, peReader);

var sources = original.SyntaxTrees.Select(st =>
{
var text = st.GetText();
return new ResolvedSource(OnDiskPath: null, text, new SourceFileInfo(path, text.ChecksumAlgorithm, text.GetChecksum().ToArray(), text, embeddedCompressedHash: null));
}).ToImmutableArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToImmutableArray [](start = 15, length = 16)

Could use SyntaxTrees.SelectAsArray(...) instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this project is missing an IVT to MS.CA for this. I will punt on it for now if that's ok.

var references = original.References.ToImmutableArray();
var (compilation, isError) = bc.CreateCompilation(optionsReader, path, sources, references);

Assert.False(isError);
Assert.Equal(platform, compilation!.Options.Platform);

// TODO: we should be able to get byte-for-byte equality here.
// it will probably be necessary to expose some diagnostic facility in the Rebuild API to figure out what's wrong here.

// using var rebuildStream = new MemoryStream();
// var result = BuildConstructor.Emit(rebuildStream, new FileInfo(path), optionsReader, compilation, logger, CancellationToken.None);
// Assert.Empty(result.Diagnostics);
// Assert.True(result.Success);
// Assert.Equal(originalBytes.ToArray(), rebuildStream.ToArray());
}

[Theory]
[MemberData(nameof(s_platforms))]
public void Platform_RoundTrip_VB(Platform platform)
{
const string path = "test";

var original = CreateVisualBasicCompilation(
path,
compilationOptions: new VisualBasicCompilationOptions(outputKind: OutputKind.ConsoleApplication, platform: platform),
encoding: Encoding.UTF8,
code: @"
Class C
Shared Sub Main()
End Sub
End Class");

original.VerifyDiagnostics();

var originalBytes = original.EmitToArray(new EmitOptions(debugInformationFormat: DebugInformationFormat.Embedded));
var peReader = new PEReader(originalBytes);
Assert.True(peReader.TryOpenAssociatedPortablePdb(path, path => null, out var provider, out _));
var pdbReader = provider!.GetMetadataReader();

var factory = LoggerFactory.Create(configure => { });
var logger = factory.CreateLogger(path);
// TODO: shouldn't need to pass a logger.
var bc = new BuildConstructor(logger);

var optionsReader = new CompilationOptionsReader(logger, pdbReader, peReader);

var sources = original.SyntaxTrees.Select(st =>
{
var text = st.GetText();
return new ResolvedSource(OnDiskPath: null, text, new SourceFileInfo(path, text.ChecksumAlgorithm, text.GetChecksum().ToArray(), text, embeddedCompressedHash: null));
}).ToImmutableArray();
var references = original.References.ToImmutableArray();
var (compilation, isError) = bc.CreateCompilation(optionsReader, path, sources, references);

Assert.False(isError);
Assert.Equal(platform, compilation!.Options.Platform);

// TODO: we should be able to get byte-for-byte equality here.
// it will probably be necessary to expose some diagnostic facility in the Rebuild API to figure out what's wrong here.

// using var rebuildStream = new MemoryStream();
// var result = BuildConstructor.Emit(rebuildStream, new FileInfo(path), optionsReader, compilation, logger, CancellationToken.None);
// Assert.Empty(result.Diagnostics);
// Assert.True(result.Success);
// Assert.Equal(originalBytes.ToArray(), rebuildStream.ToArray());
}
}
}
6 changes: 4 additions & 2 deletions src/Compilers/Test/Core/CommonTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.IO;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE;
Expand Down Expand Up @@ -343,7 +344,8 @@ protected VisualBasic.VisualBasicCompilation CreateVisualBasicCompilation(
VisualBasic.VisualBasicParseOptions parseOptions = null,
VisualBasic.VisualBasicCompilationOptions compilationOptions = null,
IEnumerable<MetadataReference> referencedAssemblies = null,
IEnumerable<Compilation> referencedCompilations = null)
IEnumerable<Compilation> referencedCompilations = null,
Encoding encoding = null)
{
if (assemblyName == null)
{
Expand Down Expand Up @@ -377,7 +379,7 @@ protected VisualBasic.VisualBasicCompilation CreateVisualBasicCompilation(

AddReferencedCompilations(referencedCompilations, references);

var tree = VisualBasic.VisualBasicSyntaxTree.ParseText(code, options: parseOptions);
var tree = VisualBasic.VisualBasicSyntaxTree.ParseText(code, options: parseOptions, encoding: encoding);

return VisualBasic.VisualBasicCompilation.Create(assemblyName, new[] { tree }, references, compilationOptions);
}
Expand Down
Loading