I've migrated an asp.net core project to VS2017 RC, which now supports the ability to exclude files from a project. I've excluded two folders, which added these lines to my csproj file:
<ItemGroup>
<Content Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\lib\**" />
</ItemGroup>
This works great, except now those files don't get published anymore. How do I exclude these folders from the project but still include them on publish?
Go to Start > Settings > Update & Security > Windows Security > Virus & threat protection. Under Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions. Select Add an exclusion, and then select from files, folders, file types, or process.
In Visual Studio, right-click on the file to be excluded from build, choose Properties, Configuration Properties -> General -> Excluded From Build -> Yes -> OK. In Eclipse, right-click on the file to be excluded from build, choose Properties, C/C++ Build -> Excluded from build -> OK.
To exclude a folder, go to File > Preferences, and search for file. exclude in the search settings. You can add the pattern of the folder you don't want Visual Studio Code to open.
The following msbuild items taken from the dotnet new spa templates helped me to achieve what I believe you are after:
<ItemGroup>
<Content Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\lib\**" />
</ItemGroup>
<Target Name="GiveAName" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="npm etc etc do your stuff" />
<Exec Command="or webpack" />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="wwwroot\dist\**; wwwroot\lib\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With