Publish .NET Blazor App not working: error MSB4018: The "GenerateEnvTransform"

Viewed 15

I have a Blazor app and do a publish to the Azure App Service. As build server I use TeamCity (which should not be relevant for my problem). Unfortunately, the publish only works in Visual Studio and not on the build agents.

Publish works from Visual Studio 2022 (all updates installed) without any problems.

Publish does NOT work...

  • ...on build agent 1 with updated SDK (Win 10, .NET SDK 6.0.400, VM). Publish aborts because file is not found (see error message below).
  • ..on build agent 2 (Docker container based on image "mcr.microsoft.com/dotnet/sdk:6.0.400-windowsservercore-ltsc2019"), same error message.

I also tried .NET SDK 6.0.302 (same result).

Publish command:

"C:\Program Files\dotnet\dotnet.exe" publish C:\BuildAgent\work\3d255f5f78d1d4fd\Source\AppXyz\src\AppXyz.Blazor\AppXyz.Blazor.csproj --configuration Release -p:PublishProfile=PublishToAzure_TestDeploy -p:Username=$AppXyz -p:Password=*******

Publish profile (pubxml-File):

    <Project>
      <PropertyGroup>
        <WebPublishMethod>MSDeploy</WebPublishMethod>
        <ResourceId>/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/AppXyz_group/providers/Microsoft.Web/sites/AppXyz</ResourceId>
        <ResourceGroup>AppXyz_group</ResourceGroup>
        <PublishProvider>AzureWebSite</PublishProvider>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish>https://appxyz.azurewebsites.net</SiteUrlToLaunchAfterPublish>
        <LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
        <ExcludeApp_Data>false</ExcludeApp_Data>
        <ProjectGuid>b260ff0d-ea6d-4853-9967-dd7c999d6a5d</ProjectGuid>
        <MSDeployServiceURL>appxyz.scm.azurewebsites.net:443</MSDeployServiceURL>
        <DeployIisAppPath>AppXyz</DeployIisAppPath>
        <RemoteSitePhysicalPath />
        <SkipExtraFilesOnServer>true</SkipExtraFilesOnServer>
        <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
        <EnableMSDeployBackup>true</EnableMSDeployBackup>
        <EnableMsDeployAppOffline>true</EnableMsDeployAppOffline>
        <UserName>$AppXyz</UserName>
        <_SavePWD>true</_SavePWD>
        <_DestinationType>AzureWebSite</_DestinationType>
        <InstallAspNetCoreSiteExtension>false</InstallAspNetCoreSiteExtension>
<WebConfigEnvironmentVariables>ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.Azure.SignalR</WebConfigEnvironmentVariables>
      </PropertyGroup>
    </Project>

Error message:

[23:25:31] [dotnet publish] AppXyz.Blazor -> C:\BuildAgent\work\2f5217094732ebd\Source\AppXyz\src\AppXyz.Blazor\bin\Release\net6.0\AppXyz.Blazor.dll [23:25:33] [dotnet publish] AppXyz.Blazor -> C:\BuildAgent\work\2f5217094732ebd\Source\AppXyz\src\AppXyz.Blazor\bin\Release\net6.0\publish
[23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: The "GenerateEnvTransform" task failed unexpectedly. [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\BuildAgent\work\2f5217094732ebd\Source\AppXyz\src\AppXyz.Blazor\obj\Release\net6.0\PubTmp\EnvironmentWithLocation.transform'. [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options) [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize) [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync) [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at System.Xml.XmlWriterSettings.CreateWriter(String outputFileName) [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at System.Xml.XmlWriter.Create(String outputFileName, XmlWriterSettings settings) [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at System.Xml.Linq.XDocument.Save(String fileName, SaveOptions options) [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at Microsoft.NET.Sdk.Publish.Tasks.GenerateEnvTransform.Execute() [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [23:25:33] [dotnet publish] C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(167,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [23:25:33] [dotnet publish] [23:25:33] [dotnet publish] Build FAILED.

I have invested a lot of hours now, but just can't get to the solution and hope for your help.

Thanks, Adrian

0 Answers
Related