Repository navigation
Closed
Labels
Description
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 runin the test project folder runs properly when running directly in Windowsdotnet runin 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
dotnet-policy-service commentedon Jun 5, 2026
Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.
Clockwork-Muse commentedon Jun 5, 2026
Unrelated - MTP+xUnitV3 has built-in coverage collectors, you no longer need this package.
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"This implies that you've cloned the directory on Windows, as does the fact that
--userns keep-idhelps.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.
hansmbakker commentedon Jun 5, 2026
Good point
Thank you for the hint, I'll look into it
I created the folder on windows independent from git
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
Clockwork-Muse commentedon Jun 7, 2026
There's no need to do this.
gitignoreor similar.Ctrl+Shift+P->Dev Containers: New Dev Containerand 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).
hansmbakker commentedon Jun 7, 2026
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.
Fix apphost/bundle creation failure on chmod-hostile filesystems
Fix apphost/bundle creation failure on chmod-hostile filesystems
Fix apphost/bundle creation failure on chmod-hostile filesystems (#12…
Fix apphost/bundle creation failure on chmod-hostile filesystems (#12…