Skip to content

Commit

Permalink
Upgrade to .NET 5
Browse files Browse the repository at this point in the history
  • Loading branch information
aelij committed Aug 6, 2021
1 parent 44b73b2 commit 3229c63
Show file tree
Hide file tree
Showing 75 changed files with 176 additions and 1,160 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ jobs:
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.402
- name: Build with dotnet
run: dotnet msbuild /restore /bl /p:Configuration=Release src/RoslynPad.sln
29 changes: 24 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Project>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<PropertyGroup>
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
<TargetFrameworks Condition=" $(MSBuildProjectName.EndsWith('Windows')) ">net5.0-windows;net48</TargetFrameworks>
<TargetFramework Condition=" '$(TargetFrameworks)' == '' and $(MSBuildProjectName.Contains('Windows')) ">net5.0-windows</TargetFramework>
<TargetFramework Condition=" '$(TargetFramework)' == '' and '$(TargetFrameworks)' == '' ">net5.0</TargetFramework>
<Features>strict</Features>
<Deterministic>True</Deterministic>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<EditorPackageVersion>1.3.0</EditorPackageVersion>
<RoslynPackageVersion>3.8.0</RoslynPackageVersion>
<RoslynAssemblyVersion>3.8.0.0</RoslynAssemblyVersion>
<AvaloniaVersion>0.9.11</AvaloniaVersion>
<DotNet5Version>5.0.0</DotNet5Version>
<AvaloniaVersion>0.10.6</AvaloniaVersion>
<DotNetVersion>[5.0.*,5.0.8]</DotNetVersion>
<LangVersion>8.0</LangVersion>
<Nullable>Enable</Nullable>
<IsPackable>false</IsPackable>
Expand All @@ -20,5 +21,23 @@
<PackageTags>Roslyn;RoslynPad</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<NuGetPrefix>$(MSBuildProjectDirectory)/obj/$([System.IO.Path]::GetFileName($(MSBuildProjectDirectory)))$(MSBuildProjectExtension)</NuGetPrefix>
<NuGetProps>$(NuGetPrefix).nuget.g.props</NuGetProps>
<NuGetTargets>$(NuGetPrefix).nuget.g.targets</NuGetTargets>
</PropertyGroup>

<Import Condition=" $(MSBuildProjectName.Contains('wpftmp')) and Exists('$(NuGetProps)') " Project="$(NuGetProps)" />

</Project>
22 changes: 12 additions & 10 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<Project>
<Target Name="UpdateAppSettings" AfterTargets="Build;Publish"
Condition=" '$(UpdateAppSettings)' == 'true' and Exists('$(MSBuildProjectDirectory)\appsettings.json') ">
Condition=" '$(UpdateAppSettings)' == 'true' and Exists('$(MSBuildProjectDirectory)\appsettings.json') ">
<PropertyGroup>
<AppSettingsInputFile>$(MSBuildProjectDirectory)\appsettings.json</AppSettingsInputFile>
<AppSettingsOriginalString>"InstrumentationKey": ""</AppSettingsOriginalString>
<AppSettingsReplaceString>"InstrumentationKey": "$(RoslynPadTelemetryKey)"</AppSettingsReplaceString>
</PropertyGroup>
<WriteLinesToFile
File="$(OutDir)\appsettings.json"
Lines="$([System.IO.File]::ReadAllText($(AppSettingsInputFile)).Replace($(AppSettingsOriginalString), $(AppSettingsReplaceString)))"
Overwrite="true"
Encoding="Unicode"/>
File="$(OutDir)\appsettings.json"
Lines="$([System.IO.File]::ReadAllText($(AppSettingsInputFile)).Replace($(AppSettingsOriginalString), $(AppSettingsReplaceString)))"
Overwrite="true"
Encoding="Unicode"/>
<WriteLinesToFile
Condition=" '$(PublishDir)' != '' "
File="$(PublishDir)\appsettings.json"
Lines="$([System.IO.File]::ReadAllText($(AppSettingsInputFile)).Replace($(AppSettingsOriginalString), $(AppSettingsReplaceString)))"
Overwrite="true"
Encoding="Unicode"/>
Condition=" '$(PublishDir)' != '' "
File="$(PublishDir)\appsettings.json"
Lines="$([System.IO.File]::ReadAllText($(AppSettingsInputFile)).Replace($(AppSettingsOriginalString), $(AppSettingsReplaceString)))"
Overwrite="true"
Encoding="Unicode"/>
</Target>

<Import Condition=" $(MSBuildProjectName.Contains('wpftmp')) and Exists('$(NuGetTargets)') " Project="$(NuGetTargets)" />
</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.1.402"
"version": "5.0.302"
}
}
1 change: 0 additions & 1 deletion samples/RoslynPadReplSample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string pr
if (!EqualityComparer<T>.Default.Equals(field, value))
{
field = value;
// ReSharper disable once ExplicitCallerInfoArgument
OnPropertyChanged(propertyName);
return true;
}
Expand Down
10 changes: 4 additions & 6 deletions samples/RoslynPadReplSample/RoslynPadReplSample.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net48</TargetFrameworks>
<UseWPF>true</UseWPF>
<OutputType>WinExe</OutputType>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<NoWarn>1701;1702</NoWarn>
<Nullable>disable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Nullable>disable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RoslynPad.Editor.Windows" Version="1.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.6.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net48" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>
</Project>
</Project>
8 changes: 4 additions & 4 deletions src/RoslynPad.Avalonia/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
xmlns:codeActions="clr-namespace:Microsoft.CodeAnalysis.CodeActions;assembly=Microsoft.CodeAnalysis.Workspaces"
xmlns:codeFixes="clr-namespace:RoslynPad.Roslyn.CodeFixes;assembly=RoslynPad.Roslyn">
<Application.Styles>
<StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default" />
<StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default" />
<StyleInclude Source="resm:AvaloniaEdit.AvaloniaEdit.xaml?assembly=AvaloniaEdit" />
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<StyleInclude Source="avares://AvaloniaEdit/AvaloniaEdit.xaml" />

<Style Selector="cc|CompletionList">
<Setter Property="Template">
Expand Down Expand Up @@ -59,4 +59,4 @@
<TextBlock Text="{Binding Descriptor.Title, Mode=OneTime}" />
</DataTemplate>
</Application.DataTemplates>
</Application>
</Application>
10 changes: 6 additions & 4 deletions src/RoslynPad.Avalonia/DocumentTreeView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void ItemContainerGenerator_Dematerialized(object? sender, Avalonia.Cont

protected override void OnDataContextChanged(EventArgs e)
{
_viewModel = (MainViewModel)DataContext;
_viewModel = DataContext as MainViewModel ?? throw new InvalidOperationException("DataContext is null");
}


Expand All @@ -64,10 +64,12 @@ private void OnDocumentKeyDown(object? sender, KeyEventArgs e)
}
}

private void OpenDocument(object source)
private void OpenDocument(object? source)
{
var documentViewModel = (DocumentViewModel)((Control)source).DataContext;
_viewModel.OpenDocument(documentViewModel);
if ((source as Control)?.DataContext is DocumentViewModel documentViewModel)
{
_viewModel.OpenDocument(documentViewModel);
}
}
}
}
2 changes: 1 addition & 1 deletion src/RoslynPad.Avalonia/DocumentView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static string GetPlatformFontFamily()

private async void OnDataContextChanged(object? sender, EventArgs args)
{
_viewModel = (OpenDocumentViewModel)DataContext;
_viewModel = DataContext as OpenDocumentViewModel ?? throw new InvalidOperationException("DataContext is null");
if (_viewModel == null) return;

_viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled;
Expand Down
6 changes: 2 additions & 4 deletions src/RoslynPad.Avalonia/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ public MainWindow()
}

AvaloniaXamlLoader.Load(this);

this.AttachDevTools();
}

protected override async void OnTemplateApplied(TemplateAppliedEventArgs e)
protected override async void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnTemplateApplied(e);
base.OnApplyTemplate(e);

await _viewModel.Initialize().ConfigureAwait(true);
}
Expand Down
3 changes: 1 addition & 2 deletions src/RoslynPad.Avalonia/RoslynPad.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<AssemblyName>RoslynPad</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>RoslynPad</RootNamespace>
<ApplicationIcon>../RoslynPad/Resources/RoslynPad.ico</ApplicationIcon>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand All @@ -21,4 +20,4 @@
<ProjectReference Include="..\RoslynPad.Common.UI\RoslynPad.Common.UI.csproj" />
<ProjectReference Include="..\RoslynPad.Editor.Avalonia\RoslynPad.Editor.Avalonia.csproj" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/RoslynPad.Avalonia/Templates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Avalonia
{
public static class Templates
{
public static readonly AvaloniaProperty<DataTemplate> HeaderTemplateProperty =
public static readonly AttachedProperty<DataTemplate> HeaderTemplateProperty =
AvaloniaProperty.RegisterAttached<Control, DataTemplate>("HeaderTemplate", typeof(Templates));

public static DataTemplate GetHeaderTemplate(Control control) => control.GetValue(HeaderTemplateProperty);
Expand Down
11 changes: 9 additions & 2 deletions src/RoslynPad.Build/ExecutionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal class ExecutionHost : IExecutionHost
private bool _running;
private bool _initializeBuildPathAfterRun;
private TextWriter? _processInputStream;
private string? _dotNetExecutable;

public ExecutionPlatform Platform
{
Expand All @@ -62,7 +63,13 @@ public ExecutionPlatform Platform

public bool HasPlatform => _platform != null;

public string? DotNetExecutable { get; set; }
public string DotNetExecutable
{
get => _dotNetExecutable ?? throw new InvalidOperationException("Missing dotnet");
set => _dotNetExecutable = value;
}

private bool HasDotNetExecutable => _dotNetExecutable != null;

public string Name
{
Expand Down Expand Up @@ -434,7 +441,7 @@ public void TryRestore()

async Task RestoreAsync(Task previousTask, CancellationToken cancellationToken)
{
if (DotNetExecutable == null)
if (!HasDotNetExecutable)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/RoslynPad.Build/IExecutionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal interface IExecutionHost
{
ExecutionPlatform Platform { get; set; }
string Name { get; set; }
string? DotNetExecutable { get; set; }
string DotNetExecutable { get; set; }
ImmutableArray<MetadataReference> MetadataReferences { get; }
ImmutableArray<AnalyzerFileReference> Analyzers { get; }

Expand Down
1 change: 0 additions & 1 deletion src/RoslynPad.Build/ILDecompiler/ReflectionDisassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ private void DisassembleMethodInternal(MethodDefinition method)
}

//call convention
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
WriteEnum(method.CallingConvention & (MethodCallingConvention)0x1f, _callingConvention);

//return type
Expand Down
5 changes: 0 additions & 5 deletions src/RoslynPad.Build/RoslynPad.Build.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>RoslynPad.Build</RootNamespace>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\RoslynPad.Runtime\RoslynPad.Runtime.csproj" />
<ProjectReference Include="..\RoslynPad.Runtime.Compat50\RoslynPad.Runtime.Compat50.csproj" />
Expand Down
7 changes: 3 additions & 4 deletions src/RoslynPad.Common.UI/Dialogs/IOpenFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using RoslynPad.Annotations;

namespace RoslynPad.UI
{
Expand All @@ -21,12 +20,12 @@ public interface IOpenFileDialog

public class FileDialogFilter
{
public FileDialogFilter([NotNull] string header, [NotNull] params string[] extensions)
public FileDialogFilter(string header, params string[] extensions)
: this(header, (IList<string>)extensions)
{
}

public FileDialogFilter([NotNull] string header, [NotNull] IList<string> extensions)
public FileDialogFilter(string header, IList<string> extensions)
{
Header = header ?? throw new ArgumentNullException(nameof(header));
Extensions = extensions ?? throw new ArgumentNullException(nameof(extensions));
Expand All @@ -39,4 +38,4 @@ public FileDialogFilter([NotNull] string header, [NotNull] IList<string> extensi
public override string ToString() =>
$"{Header}|{string.Join(";", Extensions.Select(e => "*." + e))}";
}
}
}
3 changes: 1 addition & 2 deletions src/RoslynPad.Common.UI/RoslynPad.Common.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>RoslynPad.UI</RootNamespace>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="RoslynPad.Common.UI.csproj.DotSettings" />
Expand All @@ -21,4 +20,4 @@
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="System.Reactive.Core" Version="4.1.2" />
</ItemGroup>
</Project>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Composition;
using RoslynPad.Annotations;

namespace RoslynPad.UI
{
Expand All @@ -23,10 +22,10 @@ public object GetService(Type serviceType)

internal static class ServiceProviderExtensions
{
public static T GetService<T>([NotNull] this IServiceProvider serviceProvider)
public static T GetService<T>(this IServiceProvider serviceProvider) where T : class
{
if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider));
return (T)serviceProvider.GetService(typeof(T));
return serviceProvider.GetService(typeof(T)) as T ?? throw new InvalidOperationException("Unable to find service");
}
}
}
}
14 changes: 8 additions & 6 deletions src/RoslynPad.Common.UI/Utilities/DelegateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public void Execute()
{
if (_asyncAction != null)
{
var task = _asyncAction();
_ = _asyncAction();
}
else
{
_action?.Invoke();
}
}

bool ICommand.CanExecute(object parameter) => CanExecute();
bool ICommand.CanExecute(object? parameter) => CanExecute();

void ICommand.Execute(object parameter) => Execute();
void ICommand.Execute(object? parameter) => Execute();

public event EventHandler? CanExecuteChanged;

Expand Down Expand Up @@ -100,9 +100,11 @@ public void Execute(T parameter)
}
}

bool ICommand.CanExecute(object parameter) => CanExecute((T)parameter);
#pragma warning disable CS8604 // Possible null reference argument.
bool ICommand.CanExecute(object? parameter) => CanExecute((T)parameter);

void ICommand.Execute(object parameter) => Execute((T)parameter);
void ICommand.Execute(object? parameter) => Execute((T)parameter);
#pragma warning restore CS8604 // Possible null reference argument.

public event EventHandler? CanExecuteChanged;

Expand All @@ -123,4 +125,4 @@ bool IDelegateCommand.CanExecute()
}
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference or unconstrained type parameter.
}
}
}
Loading

0 comments on commit 3229c63

Please sign in to comment.