avaloniaui / avalonia-dotnet-templates Goto Github PK
View Code? Open in Web Editor NEWAvalonia Templates for `dotnet new`
License: MIT License
Avalonia Templates for `dotnet new`
License: MIT License
Describe the bug
Using a brand new project created from the Avalonia xplat
template, on MacOS Monterey, it is not possible to build the iOS project.
To Reproduce
Steps to reproduce the behavior:
dotnet new avalonia.xplat
dotnet workload restore
dotnet restore
cd {myproject}.iOS
dotnet run
error CS0012: The type 'UIResponder' is defined in an assembly that is not referenced. You must add a reference to assembly 'Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'.
Expected behavior
I should be able to build the iOS application and launch it on the Simulator like the Avalonia Wordle application.
Desktop (please complete the following information):
Additional context
Could not isolate the difference between the Wordle application and the created application from the template. The Avalonia Wordle sample application compiles and launches, but crashes on Startup. Would appreciate a workaround until the next stable version is published if this can be solved.
I just followed the docs to set up a .Net Core App. While the template was created properly and I can even run the app, Visual Studio throws a bunch of errors:
I tried rebuilding, restoring nuget packages, clean+rebuild ... not sure what I'm missing here.
I was easy to get up and running, but handle Button Click have to using Avalonia.Interactivity
. I think started should include that important namespace by default.
And I can not find the template from nuget.org
Unable to ADD Avalonia templates to Rider Jetbrain on linux
Roots.xml was needed to make sure that trimming and AOT works. Now with preview5 it's not needed anymore.
Instead, to keep user applications non-trimmable, it might make sense to add TrimmableRootAssembly to the csproj instead targeting current project and same comment about compiled bindings as here https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/master/templates/csharp/app-mvvm/Roots.xml#L2.
XPlat template, MainView.xaml has hardcoded Background and Foreground.
https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/master/templates/fsharp/xplat/AvaloniaTest/Views/MainView.axaml
https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/master/templates/csharp/xplat/AvaloniaTest/Views/MainView.axaml
I haven't tested it yet, but it might be a good idea to support NET 5.0 on newly created APPs since .NET 5.0 is not far from .NET 3.0 in respect of user code.
Please consider pushing Avalonia.Templates.NetCore
package to nuget.org. It will give us an ability to use command like dotnet new --install Avalonia.Templates.NetCore
to get a template without cloning the whole repo.
Hello!
Consider using csproj instead of nuspec.
Since I haven't seen the days when packages were build with nuget, it seems difficult for me to use nuspec. To me easier to use dotnet pack
Example csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>0.1.0</PackageVersion>
<PackageId>Avalonia.Templates</PackageId>
<Title>Avalonia Templates</Title>
<Authors>AvaloniaUI</Authors>
<Description>.NET templates for Avalonia</Description>
<PackageTags>dotnet-new dotnet-template avalonia</PackageTags>
<PackageProjectUrl>https://github.com/AvaloniaUI/avalonia-dotnet-templates</PackageProjectUrl>
<RepositoryUrl>https://github.com/AvaloniaUI/avalonia-dotnet-templates.git</RepositoryUrl>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputPath>bin</OutputPath>
<NoPackageAnalysis>true</NoPackageAnalysis>
<NoDefaultExcludes>true</NoDefaultExcludes>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
</PropertyGroup>
<ItemGroup>
<Content Include="app\**\*;app-mvvm\**\*;resource-dictionary\**\*;style\**\*;usercontrol\**\*;window\**\*;"
Exclude="**\bin\**;**\obj\**" />
<Compile Remove="**\*" />
</ItemGroup>
</Project>
We can also add something like <PackageLicenseExpression>MIT</PackageLicenseExpression>
Or do you have any insight on how to accomplish such a thing?
I'm not really sure how else to describe the issue. The blog post you link to specifically says that there needs to be a template.config\template.json
file for dotnet new --install
to work. However, that file doesn't exist on the repo, and pointing dotnet new --install
to a clone of the repo doesn't do anything.
Ultimately I had to find the templates here, which finally gave the correct way to install them:
dotnet new --install "VitalElement.AvalonStudio.Templates"
Is it possible to update the documentation to correct this?
Currently ViewLocator in the templates is an easy way to make configure multiple view + view models soltuion. But even then for proper navigation it would require a bit more research and understanding, than simple view locator can give.
On the other side, current view locator is not trimming nor AOT friendly. Making it so would make default template way too complex.
Proposal: in the default templates we should remove view locator. Main view model is already set implicitly on the main window/view by the App.xaml.cs.
Running a default project and upgrading to the latest 0.8.1 build produced compilation errors saying "UseReactiveUI()" wasn't a method on AppBuilder. This was do to an additional using Avalonia.ReactiveUI
not being present. When 0.8.1 ships the templates should be updated.
When I print dotnet new avalonia.xplat
, dotnet creates app with 11.0.0-preview2 version. Is there a way to create template, based on 0.10.18.2 f.e. version, because CSharpMath (https://github.com/verybadcat/CSharpMath) doesn't work on Avalonia 11.0.0, producing error "Could not load file or assembly 'Avalonia.Visuals, Version=0.10.0.0 ..."
Something like this:
dotnet new avalonia.xplat -A 0.10.18.2
Describe the bug
dotnet new
generated avalonia solutions are broken when the solution directory contains a hyphen.
To Reproduce
dotnet new avalonia.xplat -o avalonia-test
avalonia-test\avalonia-test.sln
This repros even without the -o
switch if the current directory contains a hyphen.
The solution is full of bad relative paths to project files, so all the projects fail to load:
It becomes clear why this is when the created project files are compared to what's in the sln file:
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "avalonia_test", "avalonia_test\avalonia_test.csproj", "{EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}"
EndProject
Note how the hyphen in the solution directory name has been changed to the underscore character. Yet this translation did not actually happen on disk: the project directories and project filenames use a hyphen.
The generated ProjectReference items in the project files have a similar bug in using underscore instead of hyphen.
Expected behavior
The solution loads successfully in Visual Studio.
The project files use a hyphen and so do references to those projects in the sln file.
Desktop (please complete the following information):
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
When using Mvvm Toolkit (CommunityToolkit.Mvvm
), you get duplicate validations from both Mvvm Toolkit and Avalonia both running the validation. See AvaloniaUI/Avalonia#8397
This is a non-obvious issue with a non-obvious solution and should be included in the CommunityToolkit.Mvvm
template's output by default. I still use the same solution as I mentioned in the other issue: add the following to OnFrameworkInitializationCompleted()
:
ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin);
Not everybody likes the ReactiveUI. Some people would prefer community toolkit framework.
Also, we shouldn't force people to use MVVM template at all.
Description
I get errors when trying to run an application created from the Avalonia template.
Environment
OS: Ubuntu 18.04.02
.NET Core: 2.2.202
VS Code
Steps
dotnet new avalonia.mvvm
sudo dotnet run --framework netcoreapp2.1
When I'm running dotnet run I get these errors:
Unhandled Exception: System.IO.FileNotFoundException: Unable to find view for ak_window.App
at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Type type, Object rootInstance) in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\AvaloniaXamlLoader.cs:line 90
at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Object obj) in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\AvaloniaXamlLoader.cs:line 45
at ak_window.App.Initialize() in /home/darksait88/Документы/ak_window/App.xaml.cs:line 10
at Avalonia.Controls.AppBuilderBase`1.Setup() in D:\a\1\s\src\Avalonia.Controls\AppBuilderBase.cs:line 302
at Avalonia.Controls.AppBuilderBase`1.Start(AppMainDelegate main, String[] args) in D:\a\1\s\src\Avalonia.Controls\AppBuilderBase.cs:line 153
at ak_window.Program.Main(String[] args) in /home/darksait88/Документы/ak_window/Program.cs:line 12
Hello,
I just tried with v0.10.7, I get this every time.
I think it's because I have F# tools installed and it ends up with duplicate names?
With v0.10.3, it works with these packages installed :
I'm on Windows with VS 2019 and .net5.0, but I do have VS2022 and .net6.0 preview installed.
Thanks,
Kevin
There may be good reasons not to do this? But would certainly have saved me some confusion
<Application.Styles>
<FluentTheme Mode="Light" />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
</Application.Styles>
Edit: Ahh perhaps because there is no package ref for Avalonia.Controls.DataGrid, it's brought in by Avalonia.Diagnostics for debug build config?
Because we use XamlNameReferenceGenerator the InitializeComponent is generated there and causes null reference exception when accessing generated fields.
When creating a new project from the mvvm-template a default .gitignore
is deployed that contains an ignore for .idea
.
Please don't add .idea
in the ignores: When Rider creates an .idea
folder, it will place a .gitignore
in there, which will contain the "correct" ignores for working with Rider.
It is able to write in Visual Basic with Avalonia now. It would be more easier if templates for Visual Basic were added.
The MVVM template is broken:
dotnet new -i Avalonia.Templates
dotnet new avalonia.mvvm
dotnet build
error NU1108: Cycle detected.
error NU1108: Avalonia -> Avalonia (>= 0.10.18).
More context:
Without that developers would continue to be confused with how to access native APIs.
Alternatively, we can write small docs about it.
Is there a possibility for a VB implementation of this template? I have a lot of vb apps that we are wanting to convert....
Or can the templates be modified locally to use VB as the underlying language? If so, where are these templates located after the install?
Thanks In Advance
I have tried to use the xplat template and was kind of surprised that the main project https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/master/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj has <TargetFramework>netstandard2.0</TargetFramework>
while all the platform specific projects like https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/master/templates/csharp/xplat/AvaloniaTest.Android/AvaloniaTest.Android.csproj use .NET 6 e.g. <TargetFramework>net6.0-android</TargetFramework>
or https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/master/templates/csharp/xplat/AvaloniaTest.Desktop/AvaloniaTest.Desktop.csproj has e.g. <TargetFramework>net6.0</TargetFramework>
.
As the development, after creating a new project based on the template with e.g. dotnet new avalonia.xplat
, happens on the main project where I, for instance, then tried to add a NuGet package written for .NET 5, I got a message that the package is not compatible with .NET standard 2.0. I had to edit the main project's TargetFramework
before being able to add and use the NuGet package.
I am wondering what the reason is for having the main project use <TargetFramework>netstandard2.0</TargetFramework>
although the dedicated projects derived from it all use .NET 6. Is there any advantage to use <TargetFramework>netstandard2.0</TargetFramework>
? I think that is not in any way compatible with .NET 6.
Apparently, it is possible to fully remove templates from vsix and just customize CLI templates in the way they can be used from VS. It would save us a lot of time since currently we need to update templates twice. One in this repo,once in AvaloniaVS.
Materials:
https://learn.microsoft.com/en-us/shows/visual-studio-toolbox/add-a-parameter-to-a-net-core-project-template
I get NuGet errors when I'm trying to run an app created from Avalonia template.
dotnet new avalonia.app -o avapp
dotnet run
When I'm running dotnet run
I get these errors:
Unable to run your project
Your project targets multiple frameworks. Please specify which framework to run using '--framework'.
This is just some feedback, but the templates should follow the norm of creating a csproj
and a sln
like Microsoft's official templates do, instead of the user needing to create an empty solution with Visual Studio, Visual Studio for Mac or Xamarin, then creating a project with your template, and then add the created csproj
to the empty solution created earlier again using Visual Studio, Visual Studio for Mac or Xamarin. Minor nag, I know, but I feel like it's just better practice. Additionally, for Visual Studio for Mac and Xamarin, adding a project to a solution isn't very intuitive, so it leads other developers to also follow poor practices.
Describe the bug
dotnet new install Avalonia.Templates
fails on Windows on Arm / Voltera / Windows DevKit 2023
To Reproduce
on Windows 11 on Arm machine: open console, enter above command, observe error message
Expected behavior
on Windows 11 Intel x86_64 machine this is successful
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
same failure during dotnet restore
on Avalonia packages used in existing source code package that builds fine on other systems. (Also, arm64 Avalonia apps like Lunacy only shows black window on this machine)
When using version 0.8.0 of Avalonia, the command "dotnet run" returns the error message written in the issue title. This is happening on Ubuntu with .Net Core 2.2.300 installed.
This is strange because, as far as I can tell, the only framework being targetted is netcoreapp2.1.
On a possibly-related note, these templates still use netcoreapp2.1, even though the latest is netcoreapp2.2. They should probably be updated.
Hi, I'm trying to dotnet publish an Avalonia xplat web project, but get an error in the 'Linking with emcc' step: 'wasm-ld : error : initial memory too small, 23789552 bytes needed'. I see it on Mac and Windows.
To reproduce:
$ dotnet new avalonia.xplat
$ cd avaloniatest.Web
$ dotnet publish -c Release
Result:
....
[87/87] Avalonia.Base.dll.bc -> Avalonia.Base.dll.o [took 306,710s]
Linking with emcc. This may take a while ...
"/usr/local/share/dotnet/x64/packs/Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.osx-x64/6.0.4/tools/bin/wasm-ld" @/var/folders/rp/my1ll3l50yv_5tq707x3q4f00000gn/T/emscripten_vw689brm.rsp
wasm-ld : error : initial memory too small, 23789552 bytes needed
BTW I'm using AvaloniaVersion: 11.0.0-preview1, workload wasm-tools is installed . Is there a way to get publish working with xplat web project?
Hi,
I have problems with installing Avalonia on raspberry.
Preconditions:
Now i want to add new templates for dotnet with steps
After pressing install program hangs in loop. What i'm doing wrong?
Thanks
Using any of AvaloniaUI templates gives an exception.
$ dotnet new avalonia.app
Object reference not set to an instance of an object.
Seems like field wasn't set somewhere.
Using the templates fails on .NET 6 (preview).
Add a global.json
to the folder and fix the .NET version to something other that 6.
> dotnet --version
6.0.100-preview.7.21379.14
> dotnet new -i Avalonia.Templates
The following template packages will be installed:
Avalonia.Templates
Avalonia.Templates is already installed, version: 0.10.7, it will be replaced with version .
Avalonia.Templates::0.10.7 was successfully uninstalled.
Success: Avalonia.Templates::0.10.7 installed the following templates:
Template Name Short Name Language Tags
---------------------------- ------------------------- -------- ---------------------------
Avalonia .NET Core App avalonia.app F# ui/xaml/avalonia/avaloniaui
Avalonia .NET Core App avalonia.app [C#] ui/xaml/avalonia/avaloniaui
Avalonia .NET Core MVVM App avalonia.mvvm F# ui/xaml/avalonia/avaloniaui
Avalonia .NET Core MVVM App avalonia.mvvm [C#] ui/xaml/avalonia/avaloniaui
Avalonia Resource Dictionary avalonia.resource ui/xaml/avalonia/avaloniaui
Avalonia Styles avalonia.styles ui/xaml/avalonia/avaloniaui
Avalonia TemplatedControl avalonia.templatedcontrol [C#] ui/xaml/avalonia/avaloniaui
Avalonia UserControl avalonia.usercontrol F# ui/xaml/avalonia/avaloniaui
Avalonia UserControl avalonia.usercontrol [C#] ui/xaml/avalonia/avaloniaui
Avalonia Window avalonia.window F# ui/xaml/avalonia/avaloniaui
Avalonia Window avalonia.window [C#] ui/xaml/avalonia/avaloniaui
> dotnet new avalonia.app
Unable to resolve the template, these templates matched your input:
Template Name Short Name Language Tags
-------------------------------------------- ------------------------- ---------- ---------------------------
... buch of asp.core ....
Avalonia .NET Core App avalonia.app F# ui/xaml/avalonia/avaloniaui
Avalonia .NET Core App avalonia.app [C#] ui/xaml/avalonia/avaloniaui
Avalonia .NET Core MVVM App avalonia.mvvm F# ui/xaml/avalonia/avaloniaui
Avalonia .NET Core MVVM App avalonia.mvvm [C#] ui/xaml/avalonia/avaloniaui
Avalonia Resource Dictionary avalonia.resource ui/xaml/avalonia/avaloniaui
Avalonia Styles avalonia.styles ui/xaml/avalonia/avaloniaui
Avalonia TemplatedControl avalonia.templatedcontrol [C#] ui/xaml/avalonia/avaloniaui
Avalonia UserControl avalonia.usercontrol F# ui/xaml/avalonia/avaloniaui
Avalonia UserControl avalonia.usercontrol [C#] ui/xaml/avalonia/avaloniaui
Avalonia Window avalonia.window F# ui/xaml/avalonia/avaloniaui
Avalonia Window avalonia.window [C#] ui/xaml/avalonia/avaloniaui
... virually everything else ...
Oh, wow. I already read about RaiseAndSetIfChanged but it was not visible in my scope. So I thought it was some old technique because the example here looks way more complicated:
https://www.reactiveui.net/docs/handbook/data-binding/avalonia
I did not expect it to be just an extension method. This is why I hate extension methods 😑
Maybe the visual studio template should include such basic binding as an example.
There current example only has a one way binding.
Originally posted by @ckorn in AvaloniaUI/Avalonia#8116 (comment)
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
In the csproj.
Should there be a template parameter?
If so, when parameter is enabled, we can inject AvaloniaUseCompiledBindingsByDefault, otherwise inject TrimmableRootAssembly from #167
This needs to be updated to work with dotnet 3.0 I do not know whether it is avalonia proper that needs to be updated or this template or both
Why does the avalonia.xplat not support F#? Both C# and F# is compiling to MSIL anyways
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
namespace dotnet
{
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToDebug()
.UseReactiveUI();
}
}
The template code generated by "dotnet new avalonia.mvvm" is missing using Avalonia.Logging.Serilog;
at Program.cs, which makes LogToDebug()
fails to build.
Print
dotnet new avalonia.usercontrol -p:n Control -n Scene
Have
namespace AvaloniaAppTemplate.Namespace
{
public partial class Scene : UserControl
{
Incorrect namescpace
To Reproduce
Steps to reproduce the behavior:
<PackageReference Include="Avalonia" Version="0.10.18"/>
https://github.com/AvaloniaUI/Avalonia.NameGenerator needs the classes to be decorated as partial to work.
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.