Dotnet core publish: include / exclude dir in output
Given aspnet project with folders:
/ /sql /WebApp /Client /wwwroot /Views
In my project.json project, I used
"publishOptions": {
"include": [
"..\\sql",
"wwwroot",
"Views",
"web.config"
]
}
And after that there dotnet publish
were folders sql
, wwwroot
and Views
.
After switching to csproj (Microsoft.NET.Sdk.Web) I got
<None Update="..\sql\**\*;wwwroot\**\*;Views\**\*">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
After msbuild15 /t:publish
(cli doesn't work for me) there is wwwroot
, Views
AND Client
only with json
files inside. Files from sql
copied but flattened.
I am also trying to change it to:
<Content Include="..\sql\**" CopyToPublishDirectory="PreserveNewest" />
<Content Remove="Client\*" CopyToPublishDirectory="Never" />
and got the same result.
How do I delete Client
and keep the folder structure for sql
?
source to share
Update:
When using VS 2017> = 15.3 or .NET CLI version> = 2.0, there is a new feature that automatically adds metadata Link
for several known item types (including Content
). This can be used like:
<Content Include="..\sql\**" LinkBase="sql" />
Original:
You can use this:
<ItemGroup>
<Content Remove="Client\**" />
<Content Include="..\sql\**" CopyToPublishDirectory="PreserveNewest" Link="sql\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup>
The content includes item link metadata, it's a bit of a hack to force MSBuild to use the relative path of the item as the target path. This is because items outside the "design cone" are not considered in AssignTargetPath
if they do not have metadata Link
( source ).
Alternative <Content Remove="..." />
you can also do this to still have files inside VS:
<Content Update="Client\**" CopyToPublishDirectory="Never" />
source to share