Skip to content

Clean the publish folder with an MSBuild target #35716

@guardrex

Description

@guardrex

Description

Per Javier ...

dotnet publish does not automatically clean the target folder before publishing. It simply generates the necessary files for deployment based on the current state of the project and places them in the specified output folder.

If you want to ensure the target folder is cleaned before publishing, you need to remove the files from the folder first. Alternatively, you might try dotnet clean (although I don't think it works for that) or you can specify a new or empty output directory for the published files through the CLI or Visual Studio.

Provide ...

  • VS approach in publish configuration: Settings > File Publish Options> Delete all existing files prior to publish

  • MSBuild target to enforce a clean publish folder ...

    <Target Name="_RemovePublishDirBeforePublishing" BeforeTargets="BeforePublish">
      <RemoveDir Directories="$(PublishDir)" Condition="'$(PublishDir)' != ''" />
    </Target>

Cross-refs:

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-9.0&tabs=visual-studio

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/host-and-deploy/index.md

Document ID

c82cf121-831d-75dd-a796-c735aad3b3e9

Platform Id

503f69d7-fc1b-3879-cc1d-b6775ebf03cc

Article author

@guardrex

Metadata

  • ID: e07aaa4d-4ad4-778f-f74a-60d8f05d9075
  • PlatformId: 503f69d7-fc1b-3879-cc1d-b6775ebf03cc
  • Service: aspnet-core
  • Sub-service: blazor

Related Issues

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions