As .NET developer I am pretty excited about Blazor and I am already using it in one of out prototypes. However as many other alpha / preview libraries and frameworks it suffers from tiny yet annoying little bugs. One of these bugs on Blazor its inability to switch from Debug to Release configuration seamlessly as other .NET project types do. So after compiling the solution / project in Debug and then deploying it in Release mode you might see the following screen:

As you can see it’s a known issue, currently present in all versions of Blazor, including the latest preview version (0.8.0-preview-*) available at the time of writing this article.

Obviously you could manually remove Debug or Release folder depending on your current configuration or write a small tools which does the same thing for you.

However you could automate the removal of the opposite / redundant folder by using good ol’ MSBuild target. Just drop the following Directory.Build.targets file into your Blazor app’s solution root folder and you will never to take care about this error again.

Alternatively you might also integrate entire <Target> element inside your Blazor standalone .csproj file

<!-- A temporary workaround for the following Blazor bug: -->
<Target Name="RemoveOppositeOutputDirectoriesForBlazor"
    <!-- ReSharper disable once UnknownProperty -->
    <OutputRoot Condition="$(AppendTargetFrameworkToOutputPath)">
    <OppositeOutputPath Include="$(OutputRoot)\Release" Condition="'$(Configuration)'=='Debug'" />
    <OppositeOutputPath Include="$(OutputRoot)\Debug" Condition="'$(Configuration)'=='Release'" />
  <Message Text="Removing the output folder of the opposite configuration: '@(OppositeOutputPath)'" 
            Condition="Exists(@(OppositeOutputPath))" />
  <RemoveDir Directories="@(OppositeOutputPath)" />