I have a .Net472 class library with WPF-controls. It is existing for some years now, originally started with VS2017, then also used with VS2019 and it used to compile fine,also with VS 2019 16.7.
Yesterday i updated to latest VS 16.8.1 to "play" with the new .Net5 and now my old projects are failing to compile, which is not good...
I´ve created a small sample project to verify the issue, and i was able to reproduce the issue quite easily, so i can exclude other reasons:
Here´s the csproj of the sample project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<UseWpf>True</UseWpf>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<None Update="SampleControl.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>
</Project>
And the project just includes one simple user control.
<UserControl x:Class="IssueSample.SampleControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" >
<Grid>
<Label Content="Issue sample" />
</Grid>
</UserControl>
When compiling i get the compile message...
The name 'InitializeComponent' does not exist in the current context.
...which points to the code behind of the UserControl.
public partial class SampleControl : UserControl
{
public SampleControl()
{
// HERE IS WHERE THE COMPILER CLAIMS, THAT "InitializeComponent" IS NOT EXISTING...
InitializeComponent();
}
}
Does anyone have an idea what might cause this issue and how to solve it? My idea was that it might have smth. to do with then new .Net5, but could not find any what might cause the issue or any hint on how to solve it.
Help would be appreciated!
Thanks a lot!