unoplatform / uno.sourcegeneration Goto Github PK
View Code? Open in Web Editor NEWA Roslyn based C# source generation framework
License: Other
A Roslyn based C# source generation framework
License: Other
I'm trying to use System.Text.Json
in a WASM project, but I have the following error at runtime.
Could not load signature of System.Text.Json.Serialization.JsonConverter`1[T]:Write due to: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.
It appears that System.Text.Json
has a dependency to Microsoft.Bcl.AsyncInterfaces
.
If I add an explicit reference to Microsoft.Bcl.AsyncInterfaces
and try to resolve any of its types (e.g. IAsyncDisposable
) , the WASM app stops working the moment I resolve the type.
Steps to reproduce the issue:
Microsoft.Bcl.AsyncInterfaces
.<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
Main
method of Program.cs
of Uno.Wasm.Sample
, have the following code.static void Main(string[] args)
{
Console.WriteLine($"Mono Runtime Mode: " + Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_MONO_RUNTIME_MODE"));
var i = 42;
var now = DateTime.Now.ToString();
Console.WriteLine($"Main! {i} {now}");
try
{
Console.WriteLine("Getting type from Microsoft.Bcl.AsyncInterfaces");
var t = typeof(IAsyncDisposable);
Console.WriteLine("Success!");
}
catch (Exception e)
{
Console.WriteLine("Something went wrong!" + e.Message);
}
}
On some systems built using system builder, the environment variable Platform
set to MCD
. This is known to break some configurations, particularly android projects.
This issue is related to the override of msbuild variables that may fail the generation:
Which means that the global variable must not be set in order for the build to run properly.
See this for more info.
Feature request
It works both with .NET Framework and .NET Core but I keep getting this message:
warning NU1701: Package 'Uno.SourceGeneration 3.0.0-dev.10' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Can you add the netstandard2.0
target?
Nuget Package:
Uno.SourceGeneration
Package Version(s):
3.0.0-dev.10
Affected platform(s):
- [ ] iOS
- [ ] Android
- [ ] WebAssembly
- [x ] Windows
- [ ] Build tasks
Visual Studio
- [x ] 2019 (version: )
- [ ] 2017 (version: )
- [ ] 2017 Preview (version: )
- [ ] for Mac (version: )
Relevant plugins
- [ ] Resharper (version: )
The new Hosted Generation mode that uses out-of-process generation re-parses projects on each build, which can take a significant amont of build time.
It is important that a persistent process, such as "VBCSCompiler.exe" can stay in memory for as long as the msbuild processes that use it are running, so the parsed projects are kept in memory.
This feature is already implemented with the in-process model, via the reuse of AppDomains.
Sample app request
I'm trying to setup code generation in one of my open-source projects. It contains a main project that is distributed as a NuGet package. I just want to generate code in the main project, using my own generator, before it's packaged.
I've read the README and the source of Uno.CodeGen multiple times and I still can't figure it out. The targets and the dependencies do not make sense to me.
Sorry to be asking this but honestly, I researched as much as I could...
Nuget Package:
Package Version(s):
1.32.0
Affected platform(s):
- [ ] iOS
- [ ] Android
- [ ] WebAssembly
- [x] Windows
- [x] macOS
- [x] Build tasks
Visual Studio
- [x] 2019 (version: Enterprise 16.5.0 Preview 1.0)
- [x] Code (version: 1.41.0)
- [ ] 2017 Preview (version: )
- [ ] for Mac (version: )
Relevant plugins
- [ ] Resharper (version: )
Source generation randomly fails with a message similar to this one:
Uno.SourceGenerationTasks.targets: error : Error reading response
Generation does not fail.
For some unknown reason, the generation host crashes, resulting in this error. It sometimes can fail with an ExecutionEngineException
.
The source generation fails code in a net47 project that references a netstandard2.0.
A possible workaround is to include a net47 target framework in the referenced project.
See this roslyn issue: dotnet/roslyn#23114
I started writing a simple NullParamaterCheck source generator, but I have the following exception when my test project builds (the project which is using the generator):
Generation failed for MyNamespace.NullParameterCheckAspect. System.MissingMethodException: Method not found: 'Microsoft.CodeAnalysis.Compilation Uno.SourceGeneration.SourceGeneratorContext.get_Compilation()'.
at MyNamespace.NullParameterCheckAspect.Execute(SourceGeneratorContext context)
at Uno.SourceGeneration.Host.SourceGeneratorHost.<>c__DisplayClass2_0.b__13(ValueTuple`2 generatorDef) in C:\projects\uno-sourcegeneration\src\Uno.SourceGenerationHost.Shared\SourceGeneratorHost.cs:line 155 MyNamespace.Tests C:\Git\MyNamespace\solution\packages\Uno.SourceGenerationTasks\build\net45\Uno.SourceGenerationTasks.targets 101
I'm using paket for package management and am currently using version 1.26 of your library, currently struggling to get a prerelease version...
Using VS2017 15.8.4 and projects which target 4.6.2
The start of the generator looks like that:
public override void Execute(SourceGeneratorContext context)
{
var logger = context.GetLogger();
var compilation = context.Compilation;
If i remove var compilation = context.Compilation; I can successfully log to the build output.
Is this known, am I doing something wrong?
I guess it's not directly related to Uno.SourceGeneration.
Do you have any idea how to get solution's path?
Thanks in advance.
Building using SourceGenerators and .NET 5 Preview 5.0.100-preview.3.20216.6.
Build succeeds.
Build under Linux or macos.
Nuget Package:
Package Version(s):
Affected platform(s):
- [ ] iOS
- [ ] Android
- [ ] WebAssembly
- [ ] Windows
- [x] Build tasks
Visual Studio
- [ ] 2017 (version: )
- [ ] 2017 Preview (version: )
- [ ] for Mac (version: )
Relevant plugins
- [ ] Resharper (version: )
I was trying to implement a SourceGenerator that automatically generates ViewBase classes for all views in a project.
As a result, I ran into a limitation where SourceGenerator from Uno is not able to find the code from my generator. It seems to me that at the moment this is an insurmountable obstacle for SourceGenerators.
1>CSC : error UXAML0001: The type {using:Dedoose.Views}NavigationViewBase could not be found
1>CSC : error UXAML0001: Processing failed for file C:\Users\haven\source\repos\DedooseV2\Dedoose.Apps\src\shared\Dedoose.Apps.Uno.Shared\Views\Navigation\NavigationView.xaml (System.InvalidOperationException: The type {using:Dedoose.Views}NavigationViewBase could not be found
But this can be done within the Uno generator.
At the moment, using my generator looks like this:
<ViewBaseGenerator_Namespace>Dedoose.Views</ViewBaseGenerator_Namespace>
<ItemGroup Label="ViewBase">
<AdditionalFiles Include="..\..\shared\Dedoose.Apps.Shared\Views\**\*.xaml.cs" ViewBaseGenerator_BaseClass="ReactiveUI.Uno.ReactiveUserControl" ViewBaseGenerator_ViewModelNamespace="Dedoose.ViewModels" Visible="False" />
<!-- Exclude ReactivePage view -->
<AdditionalFiles Remove="..\..\shared\Dedoose.Apps.Shared\Views\Navigation\MainView.xaml.cs" />
</ItemGroup>
It generates this code:
namespace Dedoose.Views
{
public abstract partial class NavigationViewBase
: ReactiveUI.Uno.ReactiveUserControl<Dedoose.ViewModels.NavigationViewModel>
{
}
//...
}
Generator repository: https://github.com/HavenDV/ViewBaseGenerator/
To remove boilerplate code
All
Feature request
When using .NET 5.0 Preview 1, results in the error:
/Users/antao.almada/.nuget/packages/uno.sourcegenerationtasks/2.0.0-dev.308/build/netstandard1.0/Uno.SourceGenerationTasks.targets(127,2): error : Exec format error [/Users/antao.almada/Projects/NetFabric.Hyperlinq/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj]
Install .NET 5.0 Preview 1 and compile the generator project.
Nuget Package:
`Uno.SourceGeneration`
Package Version(s):
`2.0.0-dev.308`
Affected platform(s):
- [ ] iOS
- [ ] Android
- [ ] WebAssembly
- [ ] Windows
- [ x] Build tasks
Visual Studio
- [ ] 2017 (version: )
- [ ] 2017 Preview (version: )
- [ ] for Mac (version: )
- [x] .NET CLI
Relevant plugins
- [ ] Resharper (version: )
I've just started to use this project for some basic source generation tasks, and after a lot of trial and error I have it set up and working. All my projects that will consume the source generators are netcoreapp3.1 projects, but the source generator project itself doesn't seem to want to play ball if I set the target framework to netstandard2.1 or netcoreapp3.1. net48 and netstandard2.0 work, and I settled on netstandard2.0 for now.
I don't technically need anything higher since the source generator project is fairly small and simple, but it would be nice to have some of the newer .NET Core 3.x features. Is this not currently possible, or am I missing something? I've searched through the issues, looked at the source code, looked at other projects, and I can't find any indication as to whether this is supported or not.
Creating a library using :
<Project Sdk="MSBuild.Sdk.Extras/1.6.46">
<PropertyGroup>
<TargetFrameworks>uap10.0.16299</TargetFrameworks>
fails to build when including the source generation tasks package:
C:\...\1.28.0\build\uap\Uno.SourceGenerationTasks.targets(100,4): error : [Failure] Msbuild failed when processing the file 'E:\...\ClassLibraryUno.csproj' with message: C:\Program Files\dotnet\sdk\2.1.500\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets: (198, 5): Assets file 'E:\...\ClassLibraryUno\obj\project.assets.json' doesn't have a target for 'UAP,Version=v10.0'. Ensure that restore has run and that you have included 'uap10.0' in the TargetFrameworks for your project.
A project with the above definition builds.
Change uap10.0.16299
to uap10.0
, and set those two properties instead:
<TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
The uno.sourcegeneration.1.29.0-dev.161 is using net46 & uno.sourcegeneration.1.29.0-dev.178 is using net 462 )-:
If you need .net standard 2.0 support, then you can use net461
Could you please do something for this too?
Thanks in advance.
Steps to reproduce :
project A
with an abstract generator GenA
deriving from SourceGenerator
project B
, referencing project A
and create a generator GenB
deriving deriving from GenA
GenB
in a project, the Uno.SourceGeneratorTasks
won't see any useful generators to run.GenC
diriving directly from SoureGenerator
into Project B
.GenB
and GenC
will execute correctly.Currently the Context only has methods to add a new compilation unit but in my case I want a generator that will completely replace the contents of the original file. How can I do that?
The package size is too large, consider looking into its content to see if there is anything redundant or ways to reduce its size.
When creating a blank Uno app with a simple source generator, and referencing it under all heads, the macOS and iOS builds fail with the error message:
"C:\Users\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGeneratorErrorMacOSiOS.sln" (default target) (1:2) ->
"C:\Users\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGeneratorErrorMacOSiOS.iOS\SourceGeneratorErrorMacOSiOS.iOS.csproj" (default target) (3:6) ->
(_UnoSourceGenerator target) ->
MSBUILD : error : Failed to read [C:\Users\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGenerator\bin\iPhone\Debug\netstandard2.0\SourceGenerator.dll], Could not find a part of the path 'C:\Users
\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGenerator\bin\iPhone\Debug\netstandard2.0\SourceGenerator.dll'. [C:\Users\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGeneratorErrorM
acOSiOS.iOS\SourceGeneratorErrorMacOSiOS.iOS.csproj]
torErrorMacOSiOS.macOS\SourceGeneratorErrorMacOSiOS.macOS.csproj" (default target) (6:6) -> MSBUILD : error : Failed to read [C:\Users\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGentorErrorMacOSiOS.macOS\SourceGeneratorErrorMacOSiOS.macOS.csproj" (default target) (6:6) -> MSBUILD : error : Failed to read [C:\Users\agodfrey\source\repos\test\Source MSBUILD : error : Failed to read [C:\Users\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGenerator\bin\iPhoneSimulator\Debug\netstandard2.0\SourceGenerator.dll], Could not find a part of the path'C:\Users\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGenerator\bin\iPhoneSimulator\Debug\netstandard2.0\SourceGenerator.dll'. [C:\Users\agodfrey\source\repos\test\SourceGeneratorErrorMacOSiOS\SourceGeneratorErrorMacOSiOS.macOS\SourceGeneratorErrorMacOSiOS.macOS.csproj]
No other project heads have this issue.
All project heads should build successfully
Download and unzip this premade solution:
SourceGeneratorErrorMacOSiOS.zip
In a terminal, run msbuild -r
. Observe the error message.
Open "SourceGeneratorErrorMacOSiOS.iOS.csproj" and "SourceGeneratorErrorMacOSiOS.macOS.csproj" and on line 5, remove the text OutputItemType="Analyzer" ReferenceOutputAssembly="true"
from the source generator's project reference.
Run msbuild -r
again. The build is successful.
Unknown
Yes
No response
No response
iOS, macOS
No response
No response
No response
You may need to delete all bin/obj folders between builds if using MSBuild 17.0.
It's hard to know which version to use.
The following error sporadically happens when building on a heavily loaded build machine :
2018-07-06T14:14:58.2972521Z ##[error]Agent01\358\.nuget\uno.sourcegenerationtasks\1.22.0\build\MonoAndroid\Uno.SourceGenerationTasks.targets(98,4): Error : Generation failed for Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator. System.AggregateException: An error occurred while writing to logger(s). ---> System.Runtime.Remoting.RemotingException: Object '/3011ddec_8e68_49d3_95a0_e339e9cb548f/4editpvjty4l6fc76dzgfnxk_43.rem' has been disconnected or does not exist at the server.
at Uno.SourceGeneratorTasks.Logger.RemotableLogger2.WriteLog(Int32 logLevel, String message)
at Uno.SourceGeneratorTasks.Logger.RemoteLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter) in C:\projects\uno-sourcegeneration\src\Uno.SourceGeneratorTasks.Shared\Logger\RemoteLogger.cs:line 71
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
--- End of inner exception stack trace ---
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.Extensions.Logging.Logger`1.Microsoft.Extensions.Logging.ILogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Uno.SourceGeneratorTasks.Helpers.LogExtensions.Debug(ILogger log, String message, Exception exception) in C:\projects\uno-sourcegeneration\src\Uno.SourceGeneratorTasks.Shared\Helpers\LogExtensions.cs:line 94
at Uno.SourceGeneration.Host.SourceGeneratorHost.<>c__DisplayClass2_0.<Generate>b__13(ValueTuple`2 generatorDef) in C:\projects\uno-sourcegeneration\src\Uno.SourceGenerationHost.Shared\SourceGeneratorHost.cs:line 150
---> (Inner Exception #0) System.Runtime.Remoting.RemotingException: Object '/3011ddec_8e68_49d3_95a0_e339e9cb548f/4editpvjty4l6fc76dzgfnxk_43.rem' has been disconnected or does not exist at the server.
at Uno.SourceGeneratorTasks.Logger.RemotableLogger2.WriteLog(Int32 logLevel, String message)
at Uno.SourceGeneratorTasks.Logger.RemoteLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter) in C:\projects\uno-sourcegeneration\src\Uno.SourceGeneratorTasks.Shared\Logger\RemoteLogger.cs:line 71
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
Uno.SourceGeneration.Host.exe end after Visual Studio closed
No response
No response
None
Uno.SourceGenerationTasks
No response
Build tasks
Visual Studio 2022
17.5.3
No response
No response
This error message is not reflecting the proper issue and resolution.
This is linked to #2 and should be more explanatory.
When building an Xamarin.Android project on Azure Devops, setting the JavaSdkDirectory property is required, as the environment variable has no effect.
This property is not propagated to the Uno.SourceGeneration build context, making the generation fail.
Create or update a Directory.Build.props
file with this content:
<Project>
<PropertyGroup>
<JavaSdkDirectory Condition="'$(JavaSdkDirectory)'=='' and '$(JAVA_HOME_8_X64)'!=''">$(JAVA_HOME_8_X64)</JavaSdkDirectory>
</PropertyGroup>
</Project>
I'm trying to build a netstandard2.0 class library which makes use of Uno.Immutables 1.23 and Uno.CodeGen 1.23 in order to generate at build time the immutable classes.
First thing I noticed is the NU1701 warning about the Uno.SourceGenerationTasks being restored using net461 instead of netstandard2.0....
Package 'Uno.SourceGenerationTasks 1.21.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
At this point, I can still disable this warning and build the project within VS 2017 (v 15.7.5), however any attempt to build it using the dotnet CLI fails...
....nuget\packages\uno.sourcegenerationtasks\1.21.0\build\net45\Uno.SourceGenerationTasks.targets(94,3): error : Could not load type 'System.Runtime.Remoting.RemotingException' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. [F:\Tests\codegen\codegen\codegen.csproj]
0 Warning(s)
1 Error(s)
The very same issue, minus the warning obviously, happens if I target net461 instead of netstandard2.0.
Attached to this issue is a solution contaning two projects, one targetting netstandard2.0, the other net461 from which the issue is easy to reproduce.
There is a sample project attached to this issue. I can build that project using visual studio, but when I run dotnet build in command line, I receive following error:
uno.sourcegenerationtasks\1.28.0-dev.145\build\net45\Uno.SourceGenerationTasks.targets(100,4): error : Generation failed, error code -2147450740
UnoSourceGenerationIssueRepo.zip
Project gets build as like as Visual Studio's build.
Extract the repo and build that.
Nuget Package: 1.28.0-dev.145
Affected platform(s):
- [X] Build tasks
Visual Studio
- [X] 2017 (version: 15.8.5)
DotNet Core SDK 2.1.402
You can also have a look at my source code generator's codes here.
Forwarded from #62
Building for using msbuild 16.0 / VS for Mac 8.0 Preview produces the following error :
~/.nuget/packages/uno.sourcegenerationtasks/1.29.0-dev.195/build/netstandard1.0/Uno.SourceGenerationTasks.targets(99,4): error : System.TypeLoadException: Could not set up field 'Statement' due to: Could not load type of field 'Microsoft.CodeAnalysis.SQLite.Interop.SqlStatement:_rawStatement' (1) due to: Could not load file or assembly 'SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535' or one of its dependencies. assembly:~/.nuget/packages/uno.sourcegenerationtasks/1.29.0-dev.195/build/Dev15.0/Microsoft.CodeAnalysis.Workspaces.Desktop.dll type:SqlStatement member:(null) [~/SampleApp/SampleApp.csproj]
A build works properly.
Build any Uno.UI base sample using Source Generations >= 1.29.0-dev.195.
Fixing this issue can be done by adding <UnoSourceGeneratorUseGenerationHost>true</UnoSourceGeneratorUseGenerationHost>
to the iOS/macOS csproj files.
Nuget Package: 1.29.0-dev.195
Package Version(s):
Affected platform(s):
- [x] iOS
- [x] macOS
- [ ] Android
- [ ] WebAssembly
- [ ] Windows
- [ ] Build tasks
Visual Studio
- [ ] 2017 (version: )
- [ ] 2017 Preview (version: )
- [x] for Mac (version: 8.0)
Relevant plugins
- [ ] Resharper (version: )
In VS2017, design time targets are executed for a limited number of file types (XAML files to cs files).
A visual studio extension could enable partial execution of the Source Generators.
Neither Console/Debug/Trace write line methods are working.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.