I've migrated xproj
core projects to csproj
. All is working well, however I still have issues with publish configuration. Based on documentation:
https://docs.microsoft.com/en-us/dotnet/articles/core/tools/project-json-to-csproj I should be able to exclude files during publish.
I've added following lines to the f
<None Include="*.json" CopyToPublishDirectory="Never" />
<None Include="wwwroot\**\*.map;wwwroot\**\*.less;*.pdb" CopyToPublishDirectory="Never" />
<None Include="wwwroot\**\*" CopyToPublishDirectory="PreserveNewest" />
But still *.map
, .json
and .less
files are copied to publish folder. I tried different order no luck.
How to exclude certain files from publishing?
On the menu bar, choose Build > Configuration Manager. In the Project contexts table, locate the project you want to exclude from the build. In the Build column for the project, clear the check box. Choose the Close button, and then rebuild the solution.
A CSPROJ file is a C# (C Sharp) programming project file created by Microsoft Visual Studio. It contains XML-formatted text that lists a project's included files and compilation options. Developers compile CSPROJ files using MSBuild (the Microsoft Build Engine).
Short answer: use the following snippets instead:
<ItemGroup>
<Content Update="**\*.map;**\*.less;*.json" CopyToPublishDirectory="Never" />
</ItemGroup>
You could also add these patterns to the "DefaultItemExcludes" property.
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);**\*.map;**\*.less;*.json</DefaultItemExcludes>
</PropertyGroup>
Longer answer:
Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web include settings for default items. These are globs for items in your project folder that should always be compiled, embedded, copied to output, etc. There are some settings to control this, but they are not well documented.
If you want to change a metadata value (such as the CopyToPublishDirectory setting ) for an item already included by a default glob, you have to use "Update" instead of "Include".
To see what is happening under the hood, here are the default item settings for Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web
https://github.com/dotnet/sdk/blob/dev15.1.x/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.DefaultItems.props#L19-L27
https://github.com/aspnet/websdk/blob/rel/vs2017rtw/src/Web/Microsoft.NET.Sdk.Web.ProjectSystem.Targets/netstandard1.0/Microsoft.NET.Sdk.Web.ProjectSystem.props#L25-L40
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