So one of the annoying issues with Visual Studio is that it doesn't automatically include all the files required when publishing or during a build CI pipeline.

Fixing this is pretty quick and simple to do.

First we need to remove all the files from the project, so right click on the folder(s) you are wanting all of the files to be included in the project and click on Exclude From Project.

Next we want to unload the project, we do this by right clicking on the project name and then clicking on Unload Project, then right click the project name once again and click Edit Project File.

In this csproj file scroll until you find (Yours may differ slightly):

<Content Include="Web.config" />
</ItemGroup>

Above this insert the folders which you are looking to include in the project, see the example below:

<Content Include="CSS\**" />
<Content Include="Media\**" />
<Content Include="Scripts\**" />
<Content Include="Views\**" />

If you would only like to include certain files, for example minified files, you can do that as below:

<Content Include="css\*.min.css" />

Once you have entered all you require, be sure to save the project, then once again right click on the project name and click Reload Project.

Now when browsing Solution Explorer all of your files should automatically be included.

On occasion after installing/updating NuGet package(s) this can be un-done, I use GitKraken to manage my source control, so this allows me easily stage the Hunk for the new packages and discard the Hunk which un-does the above change.

Comments

Post a comment

Fields marked with an * (asterisk) are required


Recent Posts

Umbraco
Umbraco Medium Security Vulnerability - 21st Ma...

Security patch now availabl...

Umbraco
Umbraco V14 - Why we won't be offering builds,...

We explain why we will not...

Tips & Tricks
How to use Cloudflare Workers and Transform Rul...

This post explains how to m...

News
UmbHost Limited is now a Silver Umbraco Partner

We are now officially a Sil...

Umbraco
How to pass a Content Security Nonce (CSP) to G...

How to use a CSP nonce with...

ADVERTISTING
Browse Umbraco Hosting

Umbraco Hosting Starting At £20.00/month