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 cs
You might be able to satisfy your needs with a Condition
such as:
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<Content Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\lib\**" />
</ItemGroup>
EDIT:
Or perhaps try:
<ItemGroup>
<Content Condition=" '$(Configuration)' == 'Debug'" Remove="wwwroot\dist\**" />
<Content Condition=" '$(Configuration)' == 'Debug'" Remove="wwwroot\lib\**" />
</ItemGroup>
EDIT 2:
Since it looks like the IDE is going to respect the Condition
, you could instead change items from Content
to None
and add a BeforePublish
target that adds equivalent Content
items.
EDIT 3:
So to be specific, keep your original
<ItemGroup>
<Content Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\lib\**" />
</ItemGroup>
and add, just before </Project>
<Target Name="BeforePublish">
<ItemGroup>
<Content Include="wwwroot\dist\**" />
<Content Include="wwwroot\lib\**" />
</ItemGroup>
</Target>
I worked around this by adding the following lines to the PrepublishScript
target in the csproj file, since there doesn't seem to be an elegant way to do it yet.
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
<!-- Other things here already -->
<ItemGroup>
<Lib Include="wwwroot/lib/**;" />
<Dist Include="wwwroot/dist/**;" />
</ItemGroup>
<Copy SourceFiles="@(Lib)" DestinationFolder="$(PublishDir)\wwwroot\lib\%(RecursiveDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(Dist)" DestinationFolder="$(PublishDir)\wwwroot\dist\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
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>