Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet publish -o published is created nested directories with each publish

I have an ASP Core project named MyProject that I'm trying to publish to the directory MyProject\published. I run dotnet publish -o published. This works correctly the first time. However, the second time that I run this, the files get published to MyProject\published\published. The third time it gets published to MyProject\published\published\published, and so on. Why does each subsequent publish create one more nested directory, rather than just overwriting MyProject\published?

like image 343
Ben Rubin Avatar asked Jan 18 '26 02:01

Ben Rubin


2 Answers

That seems is a known issue about dotnet sdk :

https://github.com/dotnet/sdk/issues/377

https://github.com/dotnet/cli/issues/2855

The current alternatives appear to be manually deleting stale files or adding custom tasks for cleanups.

like image 158
Nan Yu Avatar answered Jan 20 '26 21:01

Nan Yu


This is now mentioned officially in the documentation: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish

First, delete your current bin/release-folder (otherwise it won't work!). Then you can add

<DefaultItemExcludes>$(DefaultItemExcludes);publish**</DefaultItemExcludes>

to a PropertyGroup element in the .csproj file. The above example assumes, the publish-folder is named publish (please change it if necessary)

like image 26
Peter Widmer Avatar answered Jan 20 '26 20:01

Peter Widmer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!