microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
234 stars 13 forks source link

[BUG] Error referencing InitializeComponent in public App() constructor, but Build succeeded. #1018

Open AleksandarDevic opened 8 months ago

AleksandarDevic commented 8 months ago

Describe the Issue

When I create a simple MAUI project, in file MauiApp1\Platforms\Windows\App.xaml.cs for method InitializeComponent I get a compiler error: 'App' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?)CS1061.

But when I do dotnet build I get info Build Succeeded!

image

Steps To Reproduce

  1. I created a simple MAUI project.

  2. In file MauiApp1\Platforms\Windows\App.xaml.cs, for method InitializeComponent I get compiler error: 'App' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?)CS1061.

  3. But when I do dotnet build I get info Build Succeeded!

Expected Behavior

The compiler should recognize the method InitializeComponent from MauiWinUIApplication class.

Environment Information

mauroa commented 8 months ago

Hi @AleksandarDevic. In the provided screenshot, I don't see the solution explorer at the left. I can only see your MAUI project folder opened as a workspace. Do you have the C#, C# DevKit and MAUI DevKit extensions installed? If so, could you please share the content of the C#, C# DevKit and .NET MAUI output panes? Thanks

AleksandarDevic commented 8 months ago

Yes, I have all the extensions and their versions you can see in the first message. Screenshoots:

  1. Output .NET MAUI image 2.Output C# Dev Kit image 3.Output C# image 4.Problems: image
github-actions[bot] commented 8 months ago

The needs-more-info label has been removed since the original bug filer has responded since the label was originally set.

fushihara commented 6 months ago

I am experiencing the same event. dotnet new wpf. I just opened a new project created with this command and now I get the same error. It does not affect the build, but it is not very good mentally.

windows 10, dotnet 8.0.204. Non wpf cli projects are fine. Visual studio not vscode is fine.

AleksandarDevic commented 4 months ago

Hi, @mauroa , any info, because the same thing on the latest .Net9?

jmlane commented 3 months ago

It also looks like this was an ongoing issue with the previous OmniSharp C# extension as well.

dibarbet commented 2 months ago

Pretty straightforward to repro with dotnet new wpf and open in VSCode with devkit enabled. Will get this error image

Works fine with C# extension standalone.

@tmeschter / @lifengl - IIRC what fixed this for the C# ext standalone was ensuring the DesignTimeMarkupCompilation target ran if available in the design time build. Not sure if that is applicable to devkit. FYI there is a good amount of upvotes on this issue here - https://github.com/dotnet/vscode-csharp/issues/5958

testov1ch commented 2 months ago

I still have the same problems. Have you already found a solution?

BDRtest1234 commented 2 months ago

The same to you ┭┮﹏┭┮

BDRtest1234 commented 2 months ago

image There is a way to fix the problem temporarily.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>ControlLearn</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;ARM64</Platforms>
    <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
    <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <PublishProfile>win-$(Platform).pubxml</PublishProfile>
+      <ImplicitUsings>enable</ImplicitUsings>
+      <Nullable>enable</Nullable>
+      <SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
+      <WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
    <UseWinUI>true</UseWinUI>
    <EnableMsixTooling>true</EnableMsixTooling>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="Assets\SplashScreen.scale-200.png" />
    <Content Include="Assets\LockScreenLogo.scale-200.png" />
    <Content Include="Assets\Square150x150Logo.scale-200.png" />
    <Content Include="Assets\Square44x44Logo.scale-200.png" />
    <Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
    <Content Include="Assets\StoreLogo.png" />
    <Content Include="Assets\Wide310x150Logo.scale-200.png" />
  </ItemGroup>

  <ItemGroup>
+    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
+    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240829007" />
+    <Manifest Include="$(ApplicationManifest)" />
  </ItemGroup>

  <!--
    Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
    Tools extension to be activated for this project even if the Windows App SDK Nuget
    package has not yet been restored.
  -->
  <ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
    <ProjectCapability Include="Msix"/>
  </ItemGroup>

  <!--
    Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
    Explorer "Package and Publish" context menu entry to be enabled for this project even if
    the Windows App SDK Nuget package has not yet been restored.
  -->
  <PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
    <HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
  </PropertyGroup>
</Project>

you have to make sure that your PackageReference and the <SupportedOSPlatformVersion>&<WindowsSdkPackageVersion> are added

pundang commented 2 weeks ago

is there any info about this? this problem is very annoying and i would like to use Omnisharp instead of the C# extension