Skip to content

Commit

Permalink
Also get reference assembly dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminMichaelis committed Nov 5, 2023
1 parent a28234a commit dbfb6f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/Shared/NetCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ public static string GetNetCoreVersion()
: throw new Exception("Unable to determine .NET Core version.");
}

public static string GetLatestPreprocessorSymbol()
public static string GetCurrentNETPreprocessorSymbol()
{
string netCoreVersion = GetNetCoreVersion();
string[] versionParts = netCoreVersion.Split('.');
string majorVersion = versionParts[0];
string minorVersion = versionParts[1];
return $"NET{majorVersion}_{minorVersion}_OR_GREATER";
return $"NET{Environment.Version.Major}_{Environment.Version.Minor}_OR_GREATER";
}
}
10 changes: 5 additions & 5 deletions src/Shared/Tests/CompilerAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public static string GetTargetFileNameToCompileFromTestFileName(
public static async Task CompileAsync(string[] fileNames, string[] expectedErrorIds)
{

var test = new Test()
Test test = new()
{
CompilerDiagnostics = CompilerDiagnostics.Warnings,
ReferenceAssemblies = new ReferenceAssemblies(
"net7.0",
$"net{Environment.Version.Major}.{Environment.Version.Minor}",
new PackageIdentity(
"Microsoft.NETCore.App.Ref",
"7.0.0"),
Path.Combine("ref", "net7.0"))
NetCore.GetNetCoreVersion()),
Path.Combine("ref", $"net{Environment.Version.Major}.{Environment.Version.Minor}"))
};

List<string> fileNamesToCompile = new();
Expand Down Expand Up @@ -166,7 +166,7 @@ private static ImmutableDictionary<string, ReportDiagnostic> GetNullableWarnings

protected override ParseOptions CreateParseOptions()
=> new CSharpParseOptions(LanguageVersion, DocumentationMode.Diagnose)
.WithPreprocessorSymbols("COMPILEERROR", NetCore.GetLatestPreprocessorSymbol());
.WithPreprocessorSymbols("COMPILEERROR", NetCore.GetCurrentNETPreprocessorSymbol());

protected override IEnumerable<DiagnosticAnalyzer> GetDiagnosticAnalyzers()
=> Enumerable.Empty<DiagnosticAnalyzer>();
Expand Down

0 comments on commit dbfb6f5

Please sign in to comment.