microsoft / vscode-docker

Docker Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
Other
1.18k stars 508 forks source link

Unable to debug with Docker when project name is all capital letters (regression in Docker extension v1.29.0) #4247

Closed joeyadams-bec closed 4 months ago

joeyadams-bec commented 4 months ago

On Ubuntu 22.04, I cannot debug an ASP.NET Core app under Docker if the project name is all capital letters. But if I downgrade to Docker extension version v1.28.0, it works.

Steps:

  1. Install the VS Code extensions listed below.
  2. Run dotnet new webapi -o FOO.BAR
  3. Open the folder in VS Code (trust if prompted).
  4. Ctrl+Shift+P and pick "Docker: Add Docker Files to Workspace..."
  5. Pick .NET: ASP.NET Core
  6. Pick Linux
  7. Leave default port (in my case, 5125)
  8. Error appears in corner saying: Unable to determine project information for target 'GetProjectProperties' on project ...

In the terminal this appears as:

2024-02-24 13:31:27.842 [info] Error: Unable to determine project information for target 'GetProjectProperties' on project '/home/joey/test/webapi-docker-4/FOO.BAR/FOO.BAR.csproj' Process exited with code 1

If I delete the FOO.BAR directory and repeat the steps above with Foo.Bar instead of FOO.BAR, it works. Also, if I complete the scaffold with Foo.Bar and then rename the project to FOO.BAR, debugging fails to launch with the same error.

Environment:

Installed VS Code Extensions:

Similar issue (same error message): https://github.com/microsoft/vscode-docker/issues/3791

bwateratmsft commented 4 months ago

This has to be a regression due to https://github.com/microsoft/vscode-docker/pull/4201. @baronfel any ideas why an all-caps project file name would cause the resolved target information to be any different?

baronfel commented 4 months ago

Nothing immediately comes to mind - an https://aka.ms/binlog would help a lot to understand what's happening here. Casing + Ubuntu immedately makes me think there's some sensitivity issue in the build pipeline somewhere, which a binlog would show.

bwateratmsft commented 4 months ago

@baronfel It looks like the error is coming from the SDK, I'm able to reproduce on Windows too:

PS D:\Sandbox\FOO.BAR> dotnet build /r:false /t:GetProjectProperties /p:CustomAfterMicrosoftCommonTargets="d:\vscode-docker\resources\netCore\GetProjectProperties.targets" /p:CustomAfterMicrosoftCommonCrossTargetingTargets="d:\vscode-docker\resources\netCore\GetProjectProperties.targets" /p:InfoOutputPath="C:\Users\bwater\AppData\Local\Temp\585b710b-d675-4313-ad1c-ca3baeafe9f11708969717400-0.tmp"  "d:\Sandbox\FOO.BAR\FOO.BAR.csproj"
MSBuild version 17.9.4+90725d08d for .NET
C:\Program Files\dotnet\sdk\8.0.200\Containers\build\Microsoft.NET.Build.Containers.targets(112,5): error CONTAINER2005: The inferred image name 'FOO.BAR' c
ontains entirely invalid characters. The valid characters for an image name are alphanumeric characters, -, /, or _, and the image name must start with an a
lphanumeric character. [d:\Sandbox\FOO.BAR\FOO.BAR.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\8.0.200\Containers\build\Microsoft.NET.Build.Containers.targets(112,5): error CONTAINER2005: The inferred image name 'FOO.BAR' c
ontains entirely invalid characters. The valid characters for an image name are alphanumeric characters, -, /, or _, and the image name must start with an a
lphanumeric character. [d:\Sandbox\FOO.BAR\FOO.BAR.csproj]
    0 Warning(s)
    1 Error(s)

Is there an MSBuild property that can be set as the image name?

bwateratmsft commented 4 months ago

@baronfel nevermind, found it.

@joeyadams-bec I was able to work around the issue by adding a property to the CSPROJ file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ContainerRepository>foo.bar</ContainerRepository> <!-- Add this line -->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
  </ItemGroup>

</Project>
bwateratmsft commented 4 months ago

Property is documented here; it mentions this scenario:

If that name is invalid as a container image name, you can override it by specifying a ContainerRepository as shown in the following project file...

dbreshears commented 4 months ago

Based on above information, going to close this as appears it is an issue in the .NET SDK.