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

Feature/support library #12

Draft
wants to merge 17 commits into
base: develop
Choose a base branch
from
10 changes: 5 additions & 5 deletions .github/workflows/dotnet_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
matrix:
os: [windows-latest, ubuntu-latest]
sdk:
- { version: 3.1.407, framework: netcoreapp3.1 }
- { version: 5.0.201, framework: net5.0 }
- { version: 3.1.415, framework: netcoreapp3.1 }
- { version: 6.0.100, framework: net6.0 }

name: ${{ matrix.os }} / ${{ matrix.sdk.version }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -50,11 +50,11 @@ jobs:
run: dotnet test -c ${{ env.configuration }} -f ${{ matrix.sdk.framework }} --no-build

- name: Pack nugets
if: ${{ matrix.os == 'ubuntu-latest' && matrix.sdk.version == '5.0.201' }}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.sdk.version == '6.0.100' }}
run: dotnet pack -c ${{ env.configuration }} --no-build

- name: Upload artifact
if: ${{ matrix.os == 'ubuntu-latest' && matrix.sdk.version == '5.0.201' }}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.sdk.version == '6.0.100' }}
uses: actions/upload-artifact@v2
with:
name: ${{ env.zip-name }}
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.201
dotnet-version: 6.0.100

- name: Push nuget
if: ${{ env.release-draft == 'false' }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/dotnet_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
matrix:
os: [windows-latest, ubuntu-latest]
sdk:
- { version: 3.1.407, framework: netcoreapp3.1 }
- { version: 5.0.201, framework: net5.0 }
- { version: 3.1.415, framework: netcoreapp3.1 }
- { version: 6.0.100, framework: net6.0 }

name: ${{ matrix.os }} / ${{ matrix.sdk.version }}
runs-on: ${{ matrix.os }}
Expand All @@ -36,13 +36,13 @@ jobs:
run: dotnet restore

- name: Build main library
working-directory: src/AvaloniaProjectInfoResolver
working-directory: ./src/AvaloniaProjectInfoResolver
run: dotnet build -c ${{ env.configuration }}

- name: Build tests
working-directory: src/AvaloniaProjectInfoResolver.IntegrationTests
working-directory: ./src/AvaloniaProjectInfoResolver.IntegrationTests
run: dotnet build -c ${{ env.configuration }} -f ${{ matrix.sdk.framework }}

- name: Run tests
working-directory: src/AvaloniaProjectInfoResolver.IntegrationTests
working-directory: ./src/AvaloniaProjectInfoResolver.IntegrationTests
run: dotnet test -c ${{ env.configuration }} -f ${{ matrix.sdk.framework }} --no-build
2 changes: 1 addition & 1 deletion .run/Debug PreviewTask [Win].run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Debug PreviewTask [Win]" type="RunExe" factoryName=".NET Executable">
<option name="EXE_PATH" value="C:/Program Files/dotnet/sdk/5.0.201/MSBuild.dll" />
<option name="EXE_PATH" value="C:/Program Files/dotnet/sdk/5.0.202/MSBuild.dll" />
<option name="PROGRAM_PARAMETERS" value="-t:Rebuild" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/src/AvaloniaProjectInfoResolver.PreviewTask.Debug" />
<option name="PASS_PARENT_ENVS" value="1" />
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.0.1</VersionPrefix>
<VersionPrefix>0.0.2</VersionPrefix>
<VersionSuffix>alpha</VersionSuffix>
<Description>A utility to resolve Avalonia features from MSBuild Project File</Description>
<Authors>AvaloniaProjectInfoResolver Contributors</Authors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<!-- For test netcoreapp3.1 -->
<TargetFramework>netcoreapp3.1</TargetFramework>
<AvaloniaVersion>0.10.0</AvaloniaVersion>
<AvaloniaVersion>0.10.10</AvaloniaVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
Expand Down
4 changes: 2 additions & 2 deletions src/AvaloniaProjectInfoResolver.App/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MainWindow()
this.AttachDevTools();
#endif
this.WhenActivated(d => d(
ViewModel.ShowOpenFileDialog.RegisterHandler(ShowOpenFileDialog)));
ViewModel!.ShowOpenFileDialog.RegisterHandler(ShowOpenFileDialog)));
}

private void InitializeComponent()
Expand All @@ -30,7 +30,7 @@ private async Task ShowOpenFileDialog(InteractionContext<Unit, string?> interact
{
var dialog = new OpenFileDialog();
var fileNames = await dialog.ShowAsync(this);
interaction.SetOutput(fileNames.FirstOrDefault());
interaction.SetOutput(fileNames?.FirstOrDefault());
}
}
}
4 changes: 2 additions & 2 deletions src/AvaloniaProjectInfoResolver.App/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ private async Task UpdateTreeViewAsync(string fileName, CancellationToken cancel
var (avaloniaProjectProps, errors) = await Task.Run(
async () =>
{
var result = await ProjectInfoResolver.ResolvePreviewProjectInfoAsync(
var result = await ProjectInfoResolver.ResolvePreviewInfoAsync(
fileName, cancellationToken);
var rootNode = cancellationToken.IsCancellationRequested || result.HasError
? null
: NodesHelper.SelectRootNode(result.ProjectInfo!);
: NodesHelper.SelectRootNode(result.PreviewInfo!);
return (rootNode, result.Error);
},
cancellationToken);
Expand Down
28 changes: 18 additions & 10 deletions src/AvaloniaProjectInfoResolver.App/Nodes/NodesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@ namespace AvaloniaProjectInfoResolver.App.Nodes
{
internal static class NodesHelper
{
public static RootNode SelectRootNode(ProjectInfo projectInfo)
public static RootNode SelectRootNode(PreviewInfo previewInfo)
{
var rootNode = new RootNode();
foreach (var property in GetProperties(typeof(ProjectInfo)))
foreach (var property in GetProperties(typeof(PreviewInfo)))
{
if (property.Name == nameof(ProjectInfo.ProjectInfoByTfmArray))
switch (property.Name)
{
foreach (var info in projectInfo.ProjectInfoByTfmArray)
case nameof(PreviewInfo.AppExecInfoCollection):
{
var node = new PropertyCollectionNode(rootNode, info);
var node = new PropertyCollectionNode(rootNode, previewInfo.AppExecInfoCollection);
rootNode.Children.Add(node);
break;
}
case nameof(PreviewInfo.XamlFileInfo):
{
var node = new PropertyCollectionNode(rootNode, previewInfo.XamlFileInfo);
rootNode.Children.Add(node);
break;
}
default:
{
var node = new PropertyNode(rootNode, property.Name, (string)property.GetValue(previewInfo, null)!);
rootNode.Children.Add(node);
break;
}
}
else
{
var node = new PropertyNode(rootNode, property.Name, (string)property.GetValue(projectInfo, null)!);
rootNode.Children.Add(node);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;

namespace AvaloniaProjectInfoResolver.App.Nodes
{
Expand All @@ -12,14 +12,47 @@ internal class PropertyCollectionNode : INode

public ObservableCollection<INode> Children { get; }

public PropertyCollectionNode(RootNode parent, ProjectInfoByTfm projectInfoByTfm)
public PropertyCollectionNode(RootNode parent, IReadOnlyList<AppExecInfo> appExecInfoCollection)
{
Parent = parent;
Header = nameof(ProjectInfoByTfm);
Header = nameof(PreviewInfo.AppExecInfoCollection);
Children = new ObservableCollection<INode>();
foreach (var info in appExecInfoCollection)
{
var node = new PropertyCollectionNode(this, info);
Children.Add(node);
}
}

public PropertyCollectionNode(INode parent, XamlFileInfo xamlFileInfo)
{
Parent = parent;
Header = nameof(PreviewInfo.XamlFileInfo);
Children = new ObservableCollection<INode>(
NodesHelper.GetProperties(typeof(ProjectInfoByTfm))
NodesHelper.GetProperties(typeof(XamlFileInfo))
.Where(x => x.Name != nameof(XamlFileInfo.ReferenceXamlFileInfoCollection))
.Select(x =>
new PropertyNode(this, x.Name, (string)x.GetValue(projectInfoByTfm, null)!)));
new PropertyNode(this, x.Name, (string)x.GetValue(xamlFileInfo, null)!)));
Children.Add(new PropertyCollectionNode(this, xamlFileInfo.ReferenceXamlFileInfoCollection));
}

private PropertyCollectionNode(PropertyCollectionNode parent, AppExecInfo appExecInfo)
{
Parent = parent;
Header = nameof(AppExecInfo);
Children = new ObservableCollection<INode>(
NodesHelper.GetProperties(typeof(AppExecInfo))
.Select(x =>
new PropertyNode(this, x.Name, (string)x.GetValue(appExecInfo, null)!)));
}

private PropertyCollectionNode(
PropertyCollectionNode parent, IReadOnlyList<XamlFileInfo> referenceXamlFileInfoCollection)
{
Parent = parent;
Header = nameof(XamlFileInfo.ReferenceXamlFileInfoCollection);
Children = new ObservableCollection<INode>(
referenceXamlFileInfoCollection.Select(x => new PropertyCollectionNode(this, x)));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -21,4 +21,9 @@
<ProjectReference Include="..\AvaloniaProjectInfoResolver\AvaloniaProjectInfoResolver.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="data\ConsoleApp1\ConsoleApp1.fsproj" CopyToOutputDirectory="PreserveNewest" />
<Content Include="data\ConsoleApp1\Program.fs" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -13,26 +14,25 @@ public async Task Should_ResolvePreviewProjectInfoAsync_App_References_Avalonia(
{
var projectInfoResolver = new ProjectInfoResolver();

var result = await projectInfoResolver.ResolvePreviewProjectInfoAsync(AvaloniaAppProjPath);
var result = await projectInfoResolver.ResolvePreviewInfoAsync(AvaloniaAppProjPath);

Assert.False(result.HasError);
Assert.Equal(result.Error, string.Empty);

var info = result.ProjectInfo!;
var info = result.PreviewInfo!;
Assert.NotNull(info);
Assert.False(string.IsNullOrEmpty(info.AvaloniaPreviewerNetCoreToolPath));
Assert.False(string.IsNullOrEmpty(info.AvaloniaPreviewerNetFullToolPath));
Assert.Equal(string.Empty, info.AvaloniaResource);
Assert.False(string.IsNullOrEmpty(info.AvaloniaXaml));
Assert.Equal(string.Empty, info.TargetFrameworks);
Assert.Equal(string.Empty, info.XamlFileInfo.AvaloniaResource);
Assert.False(string.IsNullOrEmpty(info.XamlFileInfo.AvaloniaXaml));

var infoByTfm = info.ProjectInfoByTfmArray;
Assert.Single(infoByTfm);
Assert.Equal("netcoreapp3.1", infoByTfm[0].TargetFramework);
Assert.False(string.IsNullOrEmpty(infoByTfm[0].TargetPath));
Assert.Equal(".NETCoreApp", infoByTfm[0].TargetFrameworkIdentifier);
Assert.False(string.IsNullOrEmpty(infoByTfm[0].ProjectDepsFilePath));
Assert.False(string.IsNullOrEmpty(infoByTfm[0].ProjectRuntimeConfigFilePath));
var appExecInfoCollection = info.AppExecInfoCollection;
Assert.Single(appExecInfoCollection);
Assert.Equal("netcoreapp3.1", appExecInfoCollection[0].TargetFramework);
Assert.False(string.IsNullOrEmpty(appExecInfoCollection[0].TargetPath));
Assert.Equal(".NETCoreApp", appExecInfoCollection[0].TargetFrameworkIdentifier);
Assert.False(string.IsNullOrEmpty(appExecInfoCollection[0].ProjectDepsFilePath));
Assert.False(string.IsNullOrEmpty(appExecInfoCollection[0].ProjectRuntimeConfigFilePath));
}

[Fact]
Expand All @@ -41,25 +41,26 @@ public async Task Should_ResolvePreviewProjectInfoAsync_App_References_Avalonia_
var projectInfoResolver = new ProjectInfoResolver();
using var cancellationTokenSource = new CancellationTokenSource(100);

var result = await projectInfoResolver.ResolvePreviewProjectInfoAsync(
var result = await projectInfoResolver.ResolvePreviewInfoAsync(
AvaloniaAppProjPath, cancellationTokenSource.Token);

Assert.False(result.HasError);
Assert.Equal(result.Error, string.Empty);
Assert.Null(result.ProjectInfo);
Assert.Null(result.PreviewInfo);
}

[Fact]
public async Task Should_ResolvePreviewProjectInfoAsync_TaskDebug_Not_References_Avalonia()
{
var projectInfoResolver = new ProjectInfoResolver();
var projPath = "../../../../../AvaloniaProjectInfoResolver/AvaloniaProjectInfoResolver.csproj";
var projPath = "./data/ConsoleApp1/ConsoleApp1.fsproj";
projPath = new FileInfo(projPath).FullName;

var result = await projectInfoResolver.ResolvePreviewProjectInfoAsync(projPath);
var result = await projectInfoResolver.ResolvePreviewInfoAsync(projPath);

Assert.True(result.HasError);
Assert.Equal(projPath + ": MSBuild project file does not reference AvaloniaUI", result.Error);
Assert.Null(result.ProjectInfo);
Assert.Null(result.PreviewInfo);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp

open System

// Define a function to construct a message to print
let from whom =
sprintf "from %s" whom

[<EntryPoint>]
let main argv =
let message = from "F#" // Call the function
printfn "Hello world %s" message
0 // return an integer exit code
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPublishable>false</IsPublishable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="SelectInfoProjectReference" Returns="@(ProjectReference)" />
<Target Name="SelectInfoProjectPath" Returns="$(ProjectPath)" />
<Target Name="SelectInfoOutputType" Returns="$(OutputType)" />

<Target Name="SelectInfoAvaloniaResource" Returns="@(AvaloniaResource)" />
<Target Name="SelectInfoAvaloniaXaml" Returns="@(AvaloniaXaml)" />

Expand Down
Loading