10

I have an asp core 2.1 project, and I'm trying to publish via web deploy.

I have a folder called "Angular" and inside that are my source files (including some .json files for angular's config) - these get built (via a separate process "ng build") into the wwwroot/app directory ready for publish. As such, I want NOTHING from this Angular directory to end up on the published folder. But I still want the Angular folder to show up in the project / solution explorer / find in files.

At present, it is publishing the Angular folder with all .json files inside. Obviously this is bad and I need to stop this from happening. I'm pretty sure this is happening because of this... https://github.com/aspnet/websdk/blob/dev/src/ProjectSystem/Microsoft.NET.Sdk.Web.ProjectSystem.Targets/netstandard1.0/Microsoft.NET.Sdk.Web.ProjectSystem.props#L32

I am publishing using the following command:

dotnet publish C:\blah\ -c Release /p:PublishProfile=WebDeployProfile

(and also sometimes doing it via the Visual Studio Publish using the same profile, but less frequently - I notice that these function differently, which I find odd)

I have tried so many different things, both in the .csproj and .pubxml, it's getting ridiculous, and I currently believe msbuild/deploy is a total mess, and quite broken.

I am hoping someone can help me with what should be a supremely simple and easy thing to accomplish - exclude a folder from publish (whilst leaving it in the project).

3 Answers 3

23

I ran into the same issue.

I had a folder that included multiple json files that the publish process picked up and sent to the publish output.

For excluding a folder such as 'FolderYouDontWant' add the following to your .csproj file:

<ItemGroup>
    <Content Update="FolderYouDontWant\**\*.*" CopyToPublishDirectory="Never" />
</ItemGroup>

If you have specific files you are looking for to exclude rather than whole folders, use the exact file path such as:

<ItemGroup>
    <Content Update="FolderWithFile\dont-want.json" CopyToPublishDirectory="Never" />
</ItemGroup>

If you have multiple paths you can add all of the Content elements to the same ItemGroup.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me using RIDER with ASP Net Core, thanks!
4

Your .csproj file starting with "appsettings" all "appsettings.test" etc. remove publish file

  <ItemGroup>
        <Content Update="appsettings*.json" CopyToPublishDirectory="Never" /> 
      </ItemGroup>

2 Comments

Pls add some description/explanation to your answer and explain how it works and solves the problem.
your .csproj file starting with "appsettings" all "appsettings.test" etc. remove publish file
0

Here are changes to the project (.csproj) file to exclude folders/files from being published. This was tested on a .NET Core 6 project with VS 2022.

To remove a directory:

  <ItemGroup>
    <Content Remove="FolderToRemove\**" />
  </ItemGroup>

To remove an individual file:

 <ItemGroup>
    <Content Remove="SomeFolder\file.txt" />
 </ItemGroup>

To add a file back from the directory removed:

  <ItemGroup>
    <None Update="FolderToRemove\file-to-add-back.txt">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.