Automatically Include all Files in folder in Visual Studio
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
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.