Hi @Jon Hall , Welcome to Microsoft Q&A,
Q&A: There is no way to mark your own case to end.
I revised and summarized the OP's answer:
The error you are encountering, MSB4018: The "CreateAppHost" task failed unexpectedly
, is associated with a problem during the build process. Specifically, the error message System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open
indicates that there is a file in use that cannot be accessed because it is memory-mapped, which prevents other operations from being performed on it.
There are several solutions to this problem:
Clean and rebuild solution: - Right-click your solution in Solution Explorer and select Clean Solution. - After cleaning, right-click again and select Rebuild Solution.
Delete temporary files and cache: - Delete the bin
and obj
folders in your project directory. - Clear the NuGet cache using the command dotnet nuget locals all --clear
.
Update Visual Studio and .NET SDK: - Make sure your Visual Studio and .NET SDK are up to date. Sometimes updates contain fixes for issues like this. - You can check for Visual Studio updates via Help -> Check for Updates. - Update the .NET SDK by downloading the latest version from the official .NET website.
Modify project files: - You can try to modify the .csproj
file to include or exclude certain build steps. For example, if your project does not require "CreateAppHost", try disabling it. Add the following property to your project file: xml <PropertyGroup> <EnableAppHost>false</EnableAppHost> </PropertyGroup>
OP mainly solves this problem by modifying the SDK:
I fixed it! Here is what to do:
Check what SDK your project is using by opening the code of <your project>.csproj
Then look at the <TargetFramework> tag to get the SDK version:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
Then, check what SDKs you have installed. To do this, open the command prompt (Run -> cmd). In the command prompt, type
dotnet --list-sdks
This will list the SDKs you have installed. From here, you have 2 options:
- Change the .NET version in your .csproj code to one you have installed already.
- Download the SDK your .csproj is expecting to read.
Once finished with either, restart Visual Studio and reopen your project. It should now load properly.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.