You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Certain MSBuild configuration causes _wpftmp build output directories to not be deleted after each build #2930
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.
Reacted by William Kent, jonesdwg, Morten Nielsen, Jeroen van den Brink, Nick Beer, Thomas Ibel, timsparkles, HughWarrington, dady8889, Wouter de Vries and 12 more
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
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.
Reacted by msedi, Matúš Brliť, Herman Eldering, Maximilian Haru Raditya, Jaret Varn, Mike Royer, Jeremy Kiel, TrubbleAC, Matias Guijarro and Gabriele
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:
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)
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...
Reacted by msedi, Morten Nielsen, Nick Beer, Thomas Stegemann, Herman Eldering, Clinton Ingram, Nirmal Guru, Maximilian Haru Raditya, Oliver Schneider, AFract and 11 more
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.
Reacted by AFract, Markus Nißl, d3-denis-zaporozhets, Victor Chelaru and Gabriele
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.
Reacted by msedi, Nathan Alden, Sr. and Nirmal Guru
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
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:
Applies to all projects in the repository that have the UseWPF property set to true, ignoring other projects
Runs cleanup separately for each project as it builds so parallel builds don't interfere with each other
Handles alternate ArtifactsProjectName properties
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 -->
<TargetName="CleanupWpfTmp"AfterTargets="Build"Condition=" '$(UseWPF)' == 'true' ">
<ItemGroup>
<_ArtifactsBinDirectoriesInclude="$([System.IO.Directory]::GetDirectories("$(ArtifactsPath)\bin"))" />
<_WpfTmpDirectoriesInclude="@(_ArtifactsBinDirectories)"Condition="$([System.IO.Path]::GetFilename([System.String]::Copy('%(Identity)')).StartsWith('$(ArtifactsProjectName)_')) And $([System.String]::Copy('%(Identity)').EndsWith('_wpftmp'))" />
</ItemGroup>
<RemoveDirDirectories="@(_WpfTmpDirectories)" />
</Target>
</Project>
Reacted by lindexi, Maximilian Haru Raditya, SvendK and Noah Sherwin
Activity
[-]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[/+]jonesdwg commentedon Jul 3, 2020
Just confirming this is still an issue with 3.1.301. Only impacts WindowsDesktop sdk projects. In our case we have a custom
<OutputPath>vatsan-madhavan commentedon Jul 3, 2020
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.csprojitself, 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.csprojproject 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.csprojwith 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.
jonesdwg commentedon Jul 6, 2020
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:
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("$(BaseArtifactsPath)bin","$(MSBuildProjectName)_*_wpftmp"))"/> </ItemGroup> <RemoveDir Directories="@(WpfTempDirectories)" /> </Target>nathan-alden-hp commentedon Jul 6, 2020
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...
msedi commentedon Jul 16, 2020
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.
dotMorten commentedon Jul 23, 2020
This behavior has been driving me nuts as well. This shouldn't be by-design. No other project type does this.
msedi commentedon Jan 30, 2021
Any news on this?
chipplyman commentedon Apr 14, 2021
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.
32 remaining items
Implementing plugins for better separation (#39)
Certain MSBuild configuration causes _wpftmp build output directories…
Certain MSBuild configuration causes _wpftmp build output directories…
Temporary WPF build output directories not deleted after build.
AFract commentedon Jan 30, 2024
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
lindexi commentedon Jan 31, 2024
@AFract What is your code in Directory.Build.Props ?
AFract commentedon Feb 1, 2024
Hello, thank you for answering.
Here's the important part :
lindexi commentedon Feb 4, 2024
@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.chibanemourad commentedon Apr 19, 2024
To resolve this bug, you have the choice between:
Redefine the property
<AssemblyName>individually in each of yourWPFcsproj files as follows:Alternatively, in a more global way, Redefine the
ProjectFriendlyNameproperty in aDirectory.Build.propsfile as follows:Temporary WPF build output directories not deleted after build.
Update Toic.Shared.Pre.props
brantburnett commentedon Dec 26, 2024
My solution was to add the following to
Directory.Build.targetsin the root of my repository. It's probably not perfect for all use cases, but does cover several needs:UseWPFproperty set totrue, ignoring other projectsArtifactsProjectNamepropertiesSaplonily commentedon Jun 16, 2025
Also occurs when using
UseArtifactsOutput, as it modifiesBaseOutputPath.Gabboxl commentedon Dec 23, 2025
Any updates on this? Will this issue ever be fixed? Still experiencing this on .Net 10
feat(dotnet.CWT): add target `CleanupWpfTmp` by Brant Burnett