Skip to content

Certain MSBuild configuration causes _wpftmp build output directories to not be deleted after each build #2930

Open

Description

@nathan-alden-hp

.NET Core 3.1.201
Windows 10 build 18363

Problem description:

Certain MSBuild configuration causes the compiler to leave behind directories with a _wpftmp suffix after a build completes. The problem seems to be related to custom <BaseOutputPath>s.

Actual behavior:

Temporary output directories are left behind after every build. A new directory is created per build.

Expected behavior:

Temporary output directories are deleted after every build.

Minimal repro:

WpfApp1.zip

image

Activity

  1. changed the title [-]Certain MSBuild configuration causes _wpftmp build output directories to be left behind[/-] [+]Certain MSBuild configuration causes _wpftmp build output directories to not be deleted after each build[/+] on Apr 24, 2020
  2. jonesdwg commented on Jul 3, 2020

    @jonesdwg

    Just confirming this is still an issue with 3.1.301. Only impacts WindowsDesktop sdk projects. In our case we have a custom <OutputPath>

  3. vatsan-madhavan commented on Jul 3, 2020

    @vatsan-madhavan
    Member

    This is not a bug; By Design AFAICT.

    Deleting build artifacts generated by the temp projects had never been a goal.

    The only goal has been deleting the *wpftmp.csproj itself, because it is created alongside the original project inside the cone of the sources directory.

    Depending on various build configuration choices, the output directories can be named after either (a) the target assembly or (b) the project name (or something else, which is uncommon).

    When (a) is in effect, the *wpftmp.csproj project will simply happen to use the same folders under $(Obj) and $(Bin) as the original project - they happen to share the same target assembly name by design.

    When (b) is in effect, msbuild will provision *wpftmp.csproj with its own folders under $(Obj) and $(Bin) based on the project name.

    This works the same in .NET Framework and .NET Core; in SDK style projects and in older style projects.

  4. jonesdwg commented on Jul 6, 2020

    @jonesdwg

    That's interesting, thanks. In our case however this does only seems to be impact WindowsDesktop sdk projects.

    I've modified the solution provided by @nathan-alden-hp to include a wpf .net framework project and .net core console app: repro.zip

    These all pick up their output path from the Directory.build.props, but it's only the sdk style WindowsDesktop project that leaves behind the temporary directories:

    image

    From what I understand I'm probably falling into scenario b as both the output path and intermediate path are modified based on the $(MSBuildProjectName)

    <BaseArtifactsPath>$(MSBuildThisFileDirectory)artifacts\</BaseArtifactsPath><OutputPath>$(BaseArtifactsPath)bin\$(MSBuildProjectName)\</OutputPath> <BaseIntermediateOutputPath>$(BaseArtifactsPath)obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>

    NB: I only see these extra directories left over in the bin directory, the obj directory is behaving as expected.

    This does feel like a bug (or at least undesirable behaviour) and only started happening once we migrated our WPF apps to SDK style projects.

    That said, I can work around it easily enough, by adding a post build step in Directory.build.targets to delete the directories:

    <Target Name="RemoveWpfTemp" AfterTargets="Build"> <ItemGroup> <WpfTempDirectories Include="$([System.IO.Directory]::GetDirectories(&quot;$(BaseArtifactsPath)bin&quot;,&quot;$(MSBuildProjectName)_*_wpftmp&quot;))"/> </ItemGroup> <RemoveDir Directories="@(WpfTempDirectories)" /> </Target>

  5. nathan-alden-hp commented on Jul 6, 2020

    @nathan-alden-hp
    Author

    I'm not sure why it should even be "by design" for a build system to repeatedly generate new directories that appear to never be cleaned or wiped...

  6. added this to the 5.0.0 milestone on Jul 6, 2020
  7. msedi commented on Jul 16, 2020

    @msedi

    Honestly, I also don't agree that temporary files and directories will not be deleted after the build has finished.
    Also it is not deterministic when and why this happens. We changed some small detail in the project and we even don't know which option we have changed that it came to this behavior.

  8. dotMorten commented on Jul 23, 2020

    @dotMorten
    Contributor

    This behavior has been driving me nuts as well. This shouldn't be by-design. No other project type does this.

  9. msedi commented on Jan 30, 2021

    @msedi

    Any news on this?

  10. added
    Bug
    Investigate
    and removed
    Bug
    on Feb 3, 2021
  11. chipplyman commented on Apr 14, 2021

    @chipplyman

    I confirm that this bug also affects non-SDK .NET Framework projects, as suggested by the last paragraph of vatsan-madhavan's comment from Jul 3, 2020.

    I disagree with the assessment that it is not a bug. Even if the implementation is operating as designed, that merely shifts the root cause of the bug from the implementation to the design. This arguably makes it more a severe bug since it could have been caught earlier in the production pipeline and was not.

  12. 32 remaining items

  13. AFract commented on Jan 30, 2024

    @AFract

    I am here due to the same problem (.Net 7.0, VS2022 17.8.5). I have thousands of those *wpftmp folders in my build folder...
    I have a directory.build.props in my solution, I guess it is indirectly related.
    Any structural update on it ?
    Thank you

  14. lindexi commented on Jan 31, 2024

    @lindexi
    Member

    @AFract What is your code in Directory.Build.Props ?

  15. AFract commented on Feb 1, 2024

    @AFract

    Hello, thank you for answering.
    Here's the important part :

    <Project>
    	<PropertyGroup>
    		<Version>1.0.0.0</Version>
    		<AssemblyVersion>1.0.0.0</AssemblyVersion>
    		<FileVersion>1.0.0.0</FileVersion>
    		<IntermediateOutputPath>$(SolutionDir)Build\$(MSBuildProjectName)\obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
    		<OutputPath>$(SolutionDir)Build\$(MSBuildProjectName)\bin\$(Platform)\$(Configuration)\</OutputPath>
    		<Platforms>x64</Platforms>
    		<Configurations>Debug;Release</Configurations>
    	</PropertyGroup>
    	<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Any CPU'">
    		<PlatformTarget>x64</PlatformTarget>
    		<Optimize>true</Optimize>
    		<DebugType>none</DebugType>
    	</PropertyGroup>
    	<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Any CPU'">
    		<PlatformTarget>x64</PlatformTarget>
    		<DebugSymbols>true</DebugSymbols>
    		<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    	</PropertyGroup>
    </Project>
    
  16. lindexi commented on Feb 4, 2024

    @lindexi
    Member

    @AFract Sorry, I can not repeat the problem with your Directory.Build.Props. And I think that there are other preconditions I don't know about.

    Could you provisionally remove the <OutputPath> property in Directory.Build.Props to test? Maybe there can be fewer folders created.

  17. chibanemourad commented on Apr 19, 2024

    @chibanemourad

    To resolve this bug, you have the choice between:

    Redefine the property <AssemblyName> individually in each of your WPF csproj files as follows:

    <AssemblyName>Your_Assembly_Name</AssemblyName>

    Alternatively, in a more global way, Redefine the ProjectFriendlyName property in a Directory.Build.props file as follows:

    <PropertyGroup Condition="$(ProjectFriendlyName.EndsWith('_wpftmp', StringComparison.CurrentCultureIgnoreCase))">
        <ProjectFriendlyName>$([System.IO.Path]::GetFileNameWithoutExtension($(ProjectFriendlyName)))</ProjectFriendlyName>
    </PropertyGroup>
  18. added a commit that references this issue on Jul 29, 2024
  19. brantburnett commented on Dec 26, 2024

    @brantburnett

    My solution was to add the following to Directory.Build.targets in the root of my repository. It's probably not perfect for all use cases, but does cover several needs:

    1. Applies to all projects in the repository that have the UseWPF property set to true, ignoring other projects
    2. Runs cleanup separately for each project as it builds so parallel builds don't interfere with each other
    3. Handles alternate ArtifactsProjectName properties
    4. Cleans up dangling folders from previous builds, not just the current build
    <Project>
      <!-- WPF projects tend to leave dangling "_wpftmp" directories in the "artifacts/bin" directory, clean these up after build -->
      <Target Name="CleanupWpfTmp" 
              AfterTargets="Build"
              Condition=" '$(UseWPF)' == 'true' ">
        <ItemGroup>
          <_ArtifactsBinDirectories Include="$([System.IO.Directory]::GetDirectories(&quot;$(ArtifactsPath)\bin&quot;))" />
          <_WpfTmpDirectories Include="@(_ArtifactsBinDirectories)"
                              Condition="$([System.IO.Path]::GetFilename([System.String]::Copy('%(Identity)')).StartsWith('$(ArtifactsProjectName)_')) And $([System.String]::Copy('%(Identity)').EndsWith('_wpftmp'))" />
        </ItemGroup>
      
        <RemoveDir Directories="@(_WpfTmpDirectories)" />
      </Target>
    </Project>
  20. Saplonily commented on Jun 16, 2025

    @Saplonily

    Also occurs when using UseArtifactsOutput, as it modifies BaseOutputPath.

  21. Gabboxl commented on Dec 23, 2025

    @Gabboxl

    Any updates on this? Will this issue ever be fixed? Still experiencing this on .Net 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

InvestigateWindowsDesktop SDK

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions