Skip to content

Commit 44b0b5b

Browse files
authored
Add support for .NET 5.0 (#151)
1 parent ca99fc5 commit 44b0b5b

File tree

6 files changed

+43
-16
lines changed

6 files changed

+43
-16
lines changed

Common.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1212
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
1313
<TreatSpecificWarningsAsErrors />
14-
<LibTargetFrameworks Condition ="$(LibTargetFrameworks) == ''">netstandard2.0;netcoreapp2.1</LibTargetFrameworks>
15-
<AppTargetFrameworks Condition ="$(AppTargetFrameworks) == ''">net472;netcoreapp2.1;netcoreapp3.1</AppTargetFrameworks>
14+
<LibTargetFrameworks Condition ="$(LibTargetFrameworks) == ''">netstandard2.0;netcoreapp2.1;net5.0</LibTargetFrameworks>
15+
<AppTargetFrameworks Condition ="$(AppTargetFrameworks) == ''">net472;netcoreapp2.1;netcoreapp3.1;net5.0</AppTargetFrameworks>
1616
<TestTargetFramework Condition ="$(TestTargetFramework) == ''">netcoreapp3.1</TestTargetFramework>
17-
<ToolTargetFrameworks Condition ="$(ToolTargetFrameworks) == ''">netcoreapp2.1;netcoreapp3.1</ToolTargetFrameworks>
17+
<ToolTargetFrameworks Condition ="$(ToolTargetFrameworks) == ''">netcoreapp2.1;netcoreapp3.1;net5.0</ToolTargetFrameworks>
1818
<MicrosoftCodeAnalysisVersion Condition ="$(TargetFramework) == 'netcoreapp2.1'">3.0.0</MicrosoftCodeAnalysisVersion>
1919
<MicrosoftCodeAnalysisVersion Condition ="$(TargetFramework) != 'netcoreapp2.1'">3.7.0</MicrosoftCodeAnalysisVersion>
2020
<DefineConstants Condition ="$(MicrosoftCodeAnalysisVersion) == '3.0.0'">LEGACY</DefineConstants>

Source/AsyncGenerator.Tool/AsyncGenerator.Tool.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.6" />
3333
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisVersion)" />
3434
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="$(MicrosoftCodeAnalysisVersion)" />
35+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisVersion)" />
36+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="$(MicrosoftCodeAnalysisVersion)" />
3537
</ItemGroup>
3638

3739
<ItemGroup>

Source/AsyncGenerator/Configuration/AsyncCodeConfiguration.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using AsyncGenerator.Configuration.Internal;
77
using AsyncGenerator.Core.Configuration;
88
using AsyncGenerator.Core.Logging;
9+
using AsyncGenerator.Extensions.Internal;
910
using AsyncGenerator.Internal;
1011

1112
namespace AsyncGenerator.Configuration
@@ -144,11 +145,7 @@ internal AsyncCodeConfiguration ConfigureFromStream(Stream stream, IFileConfigur
144145

145146
private static string GetExecutingDirectory()
146147
{
147-
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
148-
var uri = new UriBuilder(codeBase);
149-
var assemblyPath = Uri.UnescapeDataString(uri.Path);
150-
var dir = Path.GetDirectoryName(assemblyPath);
151-
return dir;
148+
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetPath());
152149
}
153150
}
154151
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace AsyncGenerator.Extensions.Internal
10+
{
11+
internal static class AssemblyExtensions
12+
{
13+
public static string GetPath(this Assembly assembly)
14+
{
15+
#if LEGACY
16+
var path = assembly.CodeBase;
17+
#else
18+
var path = assembly.Location;
19+
#endif
20+
if (!Uri.TryCreate(path, UriKind.Absolute, out var uri))
21+
{
22+
throw new InvalidOperationException($"Invalid assembly location: '{assembly.Location}'");
23+
}
24+
25+
return Uri.UnescapeDataString(uri.AbsolutePath);
26+
}
27+
}
28+
}

Source/AsyncGenerator/Internal/SourceCodeCompiler.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Reflection;
66
using System.Text;
77
using System.Threading.Tasks;
8+
using AsyncGenerator.Extensions.Internal;
89
using Microsoft.CodeAnalysis;
910
using Microsoft.CodeAnalysis.CSharp.Scripting;
1011
using Microsoft.CodeAnalysis.Scripting;
@@ -15,12 +16,10 @@ internal class SourceCodeCompiler
1516
{
1617
public static Assembly Compile(string sourceCode)
1718
{
18-
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
19-
var uri = new UriBuilder(codeBase);
20-
var assemblyPath = Uri.UnescapeDataString(uri.Path);
19+
var assembly = Assembly.GetExecutingAssembly();
20+
var assemblyPath = assembly.GetPath();
2121
var assemblyDir = Path.GetDirectoryName(assemblyPath);
22-
23-
var assemRefs = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
22+
var assemRefs = assembly.GetReferencedAssemblies();
2423
var references = assemRefs.Select(assemblyName => assemblyName.Name + ".dll").ToList();
2524
for (var i = 0; i < references.Count; i++)
2625
{

build.cake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#tool nuget:?package=NUnit.ConsoleRunner&version=3.10.0
1+
#tool nuget:?package=NUnit.ConsoleRunner&version=3.11.1
22
//////////////////////////////////////////////////////////////////////
33
// ARGUMENTS
44
//////////////////////////////////////////////////////////////////////
@@ -86,7 +86,8 @@ Task("SetupTestFrameworkCore")
8686
@"{{
8787
""sdk"": {{
8888
""version"": ""{0}"",
89-
""rollForward"": ""latestFeature""
89+
""rollForward"": ""latestFeature"",
90+
""allowPrerelease"": ""true""
9091
}}
9192
}}", netcoreVersion);
9293
System.IO.File.WriteAllText("global.json", content);
@@ -205,7 +206,7 @@ Task("CleanPackages")
205206

206207
Task("Pack")
207208
.IsDependentOn("ClearTestFramework")
208-
.IsDependentOn("Build") // We have to build in order to include dlls for the AsyncGenerator.CommandLine project
209+
.IsDependentOn("BuildCore") // We have to build in order to include dlls for the AsyncGenerator.CommandLine project
209210
.IsDependentOn("CleanPackages")
210211
.Description("Creates NuGet packages")
211212
.Does(() =>

0 commit comments

Comments
 (0)