add tag
FoggyFinder
I've created a brand new project from Avalonia template but when I run it I got exception:

> Avalonia.Markup.Xaml.XamlLoadException: "No precompiled XAML found for AvaloniaApplication2.App, make sure to specify x:Class and include your XAML file as AvaloniaResource"

How is it possible ?



Top Answer
FoggyFinder
Another option that worth to try:

1. Rename all `.axaml` files to `.xaml`:

For example, `App.axaml` -> `App.xaml`; `App.axaml.cs` -> `App.xaml.cs`

2. Add these lines to `.csproj` file:

```xml
<ItemGroup>
  <EmbeddedResource Include="**\*.xaml">
    <SubType>Designer</SubType>
  </EmbeddedResource>
</ItemGroup>
```

3. Make sure `.csproj` doesn't contain anything that looks like

```xml
<ItemGroup>
  <EmbeddedResource Remove="App.xaml" />
</ItemGroup>
```

or

```xml
<ItemGroup>
  <None Update="App.xaml">
    <Generator>MSBuild:Compile</Generator>
  </None>
</ItemGroup>
```

For simplest project `.csproj` file should be like one below:

```xml
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <EmbeddedResource Include="**\*.xaml">
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Avalonia" Version="0.9.11" />
    <PackageReference Include="Avalonia.Desktop" Version="0.9.11" />
  </ItemGroup>
</Project>
```

Be aware: 

*`VS` breaks your `.csproj` every time you add new `Window.xaml` or `UserControl.xaml` so you have to adjust project file manually.*
Answer #2
FoggyFinder
Sadly, but this is a well known issue. For details see: 

[Avalonia.Markup.Xaml.XamlLoadException after creating project #4456](https://github.com/AvaloniaUI/Avalonia/issues/4456)

[Avalonia.Markup.Xaml.XamlLoadException #4426](https://github.com/AvaloniaUI/Avalonia/issues/4426)

[Visual Studio Template Problem #4373](https://github.com/AvaloniaUI/Avalonia/issues/4373)

Until the bug is fixed you can try next steps:

1. Update to latest version.

Usually this means the new minor version of package was released. 

For example, `csproj` file after creation looks like

```xml
  <ItemGroup>
    <PackageReference Include="Avalonia" Version="0.9.11" />
    <PackageReference Include="Avalonia.Desktop" Version="0.9.11" />
  </ItemGroup>
```

but latest package is `0.9.12` already:

```xml
  <ItemGroup>
    <PackageReference Include="Avalonia" Version="0.9.12" />
    <PackageReference Include="Avalonia.Desktop" Version="0.9.12" />
  </ItemGroup>
```

2. Close VS and remove "`.bin`"/"`.obj`" folders.

3. Reopen VS.

4. Build & Run

No guarantee that these steps will be enough but, at least, it works for me.

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.