MsBuild ignore TransformWebConfigEnabled parameter

Ouellet Francis 1 Reputation point
2025-04-17T14:07:41.4066667+00:00

For some reason MsBuild tag my obj\web.config as ReadOnly. I trying several time to find a workaround but without success.

ServiceApi failed with 1 error(s) (6.9s) → output\
    C:\Program Files\dotnet\sdk\9.0.203\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:
      The "TransformWebConfig" task failed unexpectedly.
      System.UnauthorizedAccessException: Access to the path 'D:\Projets\output\Web.config' is denied. at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
         at Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute()
         at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLogging
      Context taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

At first it seem, after I track the file with Process Monitor, that is MsSense is locking the file. I add some exclusions to prevent MsSense to lock the file but without success.

After I try to avoid the task TransformWebConfig by:

  • Set the parameter TransformWebConfigEnabled to False (in project file, also with a /p:). MsBuild ignore the parameter
  • I deleted all my Web.Release.config. Nothing TransformWebConfig it still triggered

It seem this error only happened with the SDK version of my projects. Old school project dont have this issue.

Visual Studio Setup
Visual Studio Setup
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Setup: The procedures involved in preparing a software program or application to operate within a computer or mobile device.
1,144 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.