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
192 stars 6 forks source link

[BUG] Build configuration are not functionnal in VS Code with .NET MAUI extention #1054

Closed espritm closed 2 weeks ago

espritm commented 1 month ago

Describe the Issue

I am migrating from .Net7 to .Net8 a MAUI application project. So I need to migrate from VS For Mac to VS Code too.

I have several build configurations, DebugEV1, DebugEV2 (and other for prod and release..). But I cannot use them successfully is VS Code.

Steps To Reproduce

Here are my config :

In my csproj :

  <PropertyGroup>
    <Configurations>DebugEV1;DebugEV2</Configurations>
  </PropertyGroup>

  <ItemGroup>
    <None Include="BuildConfigurations\EV1Constants.cs" />
    <None Include="BuildConfigurations\EV2Constants.cs" />
  </ItemGroup>

  <ItemGroup>
    <Compile Remove="BuildConfigurations\EV1Constants.cs" />
    <Compile Remove="BuildConfigurations\EV2Constants.cs" />
  </ItemGroup>
   <ItemGroup Condition=" '$(Configuration)'=='Debug'">
    <Compile Include="BuildConfigurations\EV2Constants.cs" />
  </ItemGroup>

  <ItemGroup Condition=" '$(Configuration)'=='DebugEV1'">
    <Compile Include="BuildConfigurations\EV1Constants.cs" />
  </ItemGroup>

  <ItemGroup Condition=" '$(Configuration)'=='DebugEV2'">
    <Compile Include="BuildConfigurations\EV2Constants.cs" />
  </ItemGroup>

In my solution folder, the EV1Constants.cs and EV2Constants.cs files, of course as well as the BuildConfigurations folder containing them. Note that this works fine in VS For Mac for years (Xamarin.Forms > .net6 Maui > .net7 Maui).

To migrate to VS Code, I had to create a launch.json file with the following :

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "DebugEV1",
            "type": "maui",
            "request": "launch",
            "preLaunchTask": "maui: Build",
            "configuration": "DebugEV1"
        },
        {
            "name": "DebugEV2",
            "type": "maui",
            "request": "launch",
            "preLaunchTask": "maui: Build",
            "configuration": "DebugEV2"
        }
    ]
}

From there I retrieve my lovely combobox "Run And Debug" DebugEV1 or DebugEV2, and it builds fine, it even run on simulator (a pleasant success after 1 week of hard try). In my bin obj folders I have the rights folder : bin/DebugEV1 or bin/DebugEV2

But, in all cases, the content of EV2Constants.cs file is used.. Where the content of EV1Constants.cs should be used if I build with DebugEV1 configuration.

Expected Behavior

If I build with the configuration DebugEV1, the EV1Constants.cs file should be used for compilation. If I build with the configuration DebugEV2, the EV2Constants.cs file should be used for compilation.

Environment Information

Visual Studio Code Version: 1.88.0 (Universal) Commit: 5c3e652f63e798a5ac2f31ffd0d863669328dc4c Date: 2024-04-03T13:28:18.899Z (6 days ago) Electron: 28.2.8 ElectronBuildId: 27744544 Chromium: 120.0.6099.291 Node.js: 18.18.2 V8: 12.0.267.19-electron.0 OS: Darwin arm64 23.1.0

.NET MAUI extension v0.9.7

C# extension v2.23.15

C# Dev Kit v1.4.29

dotnet 8.0.203

VS For Mac 17.6.10 (build 428) | VS Bug 2032240

emaf commented 2 weeks ago

@espritm Could you share a build binary log after building for DebugEV1? You can produce a build binlog by setting the MAUI Debug Verbosity to diagnostic from Settings -> Extensions -> .NET MAUI. A file named msbuild.binlog will be created next to your solution file.

espritm commented 2 weeks ago

Thanks @emaf Please find the msbuild.binlog here : msbuild.binlog.zip

I have upgraded to latests pre-releases versions : C# v2.26.13 (pre-release) C# Dev Kit v1.5.14 (pre-release) .NET MAUI v0.11.16 (pre-release)

github-actions[bot] commented 2 weeks ago

@emaf, the 'needs-more-info' label has been removed upon receiving further response from the original bug filer.

mauroa commented 2 weeks ago

This issue is related and shares root cause to this other one: https://github.com/microsoft/vscode-dotnettools/issues/1072 It was also opened by the same customer. Linking for tracking purposes

emaf commented 2 weeks ago

Thanks @espritm!

From what I can see in the binary log, EV1Constants.cs is what is passed to the compiler and not EV2Constants.cs. What are you seeing that would signal EV2Constants is being used to compile?

If you are curious about the binary log, you can inspect it using the MSBuild Structured Log Viewer.

espritm commented 2 weeks ago

Hello @emaf thank you for your answer and the link to the log viewer !

The URL used was "ev2.com" instead of "ev1.com", which is configured in those Constants.cs files.

But, I confirm upgrading to the latest pre-release versions have fix my issue: I have downgraded and analysed the binlog with this, the wrong file was taken. And with latests pre-release version of C#, C# Dev Kit and .NET MAUI extensions, the right file is taken.

emaf commented 2 weeks ago

Awesome! Thanks for confirming this is now fixed!