Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core Publish Exclude Folder (or .json files)

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).

like image 846
NightCabbage Avatar asked Dec 03 '22 19:12

NightCabbage


1 Answers

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.

like image 172
Jeremy Langley Avatar answered Dec 10 '22 20:12

Jeremy Langley