Skip to content

Building a C# AppHost fails within a devcontainer, blocking xUnit v3 test projects #129040

Closed

Description

@hansmbakker

Description

When running a test project based on xUnit v3 with MTP v2 in a .NET devcontainer running in podman, it has an System.UnauthorizedAccessException which breaks dotnet run.

Reproduction Steps

Setup a workspace with a devcontainer and a test project:

Dev container:

{
  "name": "mydevcontainer",
  "image": "mcr.microsoft.com/devcontainers/dotnet:10.0",
  "features": {
    "ghcr.io/devcontainers/features/dotnet:2": {
      "version": "10.0"
    }
  },
  "postCreateCommand": "dotnet tool install -g Microsoft.OpenApi.Kiota && dotnet restore",
  "customizations": {
    "vscode": {
      "extensions": [
        "ms-dotnettools.csdevkit",
        "ms-dotnettools.csharp"
      ]
    }
  }
}

Create a test project like this:

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

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
    <UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="coverlet.collector" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" />
    <PackageReference Include="NSubstitute" />
    <PackageReference Include="xunit.v3.mtp-v2" />
    <PackageReference Include="xunit.runner.visualstudio" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\src\projectundertest.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Using Include="Xunit" />
  </ItemGroup>

</Project>

Directory.Packages.props:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>

  <!-- Test project -->
  <ItemGroup>
    <PackageVersion Include="coverlet.collector" Version="6.0.4" />
    <PackageVersion Include="NSubstitute" Version="5.3.0" />
    <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
    <PackageVersion Include="xunit.v3.mtp-v2" Version="3.2.2" />
    <PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
  </ItemGroup>
</Project>

Expected behavior

dotnet run in the test project folder runs properly when running

  • directly in Windows AND
  • in the devcontainer

Actual behavior

  • dotnet run in the test project folder runs properly when running directly in Windows
  • dotnet run in the test project folder fails when running in the devcontainer:
$ dotnet run
/usr/share/dotnet/sdk/10.0.300/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(850,5): error MSB4018: 
  The "CreateAppHost" task failed unexpectedly.
  System.UnauthorizedAccessException: Access to the path '/workspaces/mytestproject/obj/Debug/net10.0/apphost' is denied.
   ---> System.IO.IOException: Operation not permitted
     --- End of inner exception stack trace ---
     at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
     at System.IO.FileStatus.SetUnixFileMode(SafeFileHandle handle, String path, UnixFileMode mode)
     at System.IO.File.SetUnixFileMode(String path, UnixFileMode mode)
     at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface,
   String assemblyToCopyResourcesFrom, Boolean enableMacOSCodeSign, Boolean disableCetCompat, DotNetSearchOptions dotNetSearchOptions)
     at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
     at Microsoft.NET.Build.Tasks.TaskBase.Execute()
     at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutio
  nMode howToExecuteTask)

Regression?

No response

Known Workarounds

Run sudo dotnet run

Configuration

  • podman v5.8.2
  • .NET 10
  • DevContainer based on mcr.microsoft.com/devcontainers/dotnet:10.0
  • x64 architecture
  • xUnit v3 with MTP v2
    <PackageVersion Include="coverlet.collector" Version="6.0.4" />
    <PackageVersion Include="NSubstitute" Version="5.3.0" />
    <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
    <PackageVersion Include="xunit.v3.mtp-v2" Version="3.2.2" />
    <PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />

Other information

This might be related with podman being rootless. Adding the following json to devcontainer.json helps

  "runArgs": [
    "--userns=keep-id"
  ],

<UseAppHost>false</UseAppHost> is not an option:

xUnit.net v3 test projects must build an app host (set project property 'true'). If this is not a test project, reference xunit.v3.extensibility.core instead.

Activity

  1. added
    untriaged
    on Jun 5, 2026
  2. dotnet-policy-service commented on Jun 5, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
    See info in area-owners.md if you want to be subscribed.

  3. Clockwork-Muse commented on Jun 5, 2026

    @Clockwork-Muse
    Contributor
    <PackageVersion Include="coverlet.collector" Version="6.0.4" />
    

    Unrelated - MTP+xUnitV3 has built-in coverage collectors, you no longer need this package.

    This might be related with podman being rootless. Adding the following json to devcontainer.json helps

    Note that this breaks people using docker.
    Given how "common" this need is, I've often seen it recommended to add it to containers.conf (or via environment variable), which removes it from this definition and makes docker ones work "by default"

    Actual behavior
    dotnet run in the test project folder runs properly when running directly in Windows
    dotnet run in the test project folder fails when running in the devcontainer:

    This implies that you've cloned the directory on Windows, as does the fact that --userns keep-id helps.

    1. There's some (somewhat unspecified) performance penalty for doing this, owing to the need to bridge the two filesystems
    2. It can result in odd permissions issues regardless, because Windows doesn't deal with Linux file permission bits.
    3. It can result in having a weird mix of line endings in files.

    The recommendation when using devcontainers on Windows (and perhaps generally) is to clone the repo inside a volume, which usually renders code file permissions irrelevant.

  4. hansmbakker commented on Jun 5, 2026

    @hansmbakker
    Author

    Unrelated - MTP+xUnitV3 has built-in coverage collectors, you no longer need this package

    Good point

    I've often seen it recommended to add it to containers.conf (or via environment variable), which removes it from this definition and makes docker ones work "by default"

    Thank you for the hint, I'll look into it

    This implies that you've cloned the directory on Windows, as does the fact that --userns keep-id helps.

    I created the folder on windows independent from git

    The recommendation when using devcontainers on Windows (and perhaps generally) is to clone the repo inside a volume, which usually renders code file permissions irrelevant.

    Maybe that's wise indeed, it's just that that doesn't work nice when having this workflow:

    Create workspace on windows independent -> add devcontainer -> reopen in container

  5. Clockwork-Muse commented on Jun 7, 2026

    @Clockwork-Muse
    Contributor

    Create workspace on windows independent -> add devcontainer -> reopen in container

    There's no need to do this.

    • If the remote repo already exists and has a devcontainer, cloning into a volume will auto open in the container.
    • If the remote repo already exists, but doesn't yet have a devcontainer, cloning in a volume will ask you to select an appropriate definition template. This should work even if the repo is empty.
    • If the remote repo exists, but you shouldn't pollute it by adding a devcontainer definition, you can designate a folder for the definition. This should be written before the remote repo is cloned (alas, tooling integration isn't as great here as VSCode seems to think). Or keeping it in the repo/workspace, but setting a global gitignore or similar.
    • If you're creating a new devcontainer/workspace "from scratch", you can do Ctrl+Shift+P -> Dev Containers: New Dev Container and following the prompts. When you're prompted for a name, this will be the name of the "host" volume for the new workspace. In most cases this should be sufficient for direct-to-devcontainer setup.

    There's no reason to need to create anything on the host first to bootstrap (save for the configuration directory case, which is usually rare).

  6. hansmbakker commented on Jun 7, 2026

    @hansmbakker
    Author

    My usecase was a dotnet solution I created locally in Windows (no remote repo yet) and adding a devcontainer later.

    It doesn't move your files into a volume in that case I believe.

    Appreciate the feedback on this, but hope the maintainers can still have a look why there is a permission issue with apphost while there is not with other files generated by msbuild.

  7. added 2 commits that reference this issue on Jun 12, 2026
    5071bc7
    4272452
  8. added a commit that references this issue on Jun 26, 2026
    eb60eb4
  9. removed
    untriaged
    on Jun 26, 2026
  10. added a commit that references this issue on Jul 15, 2026
    6b7d6e9
  11. locked and limited conversation to collaborators on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions