Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete folders after publish with new ASP.NET CORE 1.1 csproj file format

I am publishing an ASP.NET Core 1.1 application and I need to delete from the output a few folders (fr;nl;pt) created by a library (Fluent Validation):

<ItemGroup>
  <FluentValidationExcludedCultures Include="fr;nl;pt">
    <InProject>false</InProject>
  </FluentValidationExcludedCultures>
</ItemGroup>

<Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild">
  <RemoveDir Directories="@(FluentValidationExcludedCultures->'$(OutputPath)%(Filename)')" />
</Target>

But this does not work and the folders are still copied ... Then I tried:

<ItemGroup>
  <Content Include="fr" CopyToPublishDirectory="Never" />
  <Content Include="nl" CopyToPublishDirectory="Never" />
  <Content Include="pt" CopyToPublishDirectory="Never" />
</ItemGroup>

But this didn't work either ...

Does anyone has any idea how to make this work?

like image 569
Miguel Moura Avatar asked Mar 02 '17 17:03

Miguel Moura


People also ask

How do I delete a folder in .NET core?

You should use: dir. Delete(true); for recursively deleting the contents of that folder too.

What is Csproj file in asp net core?

csproj file tells dotnet how to build the ASP.NET application. It's one of the most important files in an ASP.NET project. An ASP.NET project can depend on third-party libraries developed by other developers. Usually, these libraries are installed as Nuget packages using Nuget package manager.

What is publish profile in MSBuild?

The publish profiles created with Visual Studio can be used with MSBuild and Visual Studio. For instructions on publishing to Azure, see Publish an ASP.NET Core app to Azure with Visual Studio. The dotnet new mvc command produces a project file containing the following root-level <Project> element: XML Copy.


2 Answers

Try to edit your csproj file and add the following section for each of the directories that you do not want to include when publishing:

<ItemGroup>
    <PublishFile Remove="directory\**" />
</ItemGroup>
like image 79
Gary Holland Avatar answered Nov 15 '22 05:11

Gary Holland


Another solution that works for build/publish

<!-- Removes FluentValidation localization folders -->
  <Target Name="AfterPackage" AfterTargets="CopyAllFilesToSingleFolderForPackage" />
  <ItemGroup>
    <FluentValidationExcludedCultures Include="cs;da;de;es;fa;fi;fr;it;ko;mk;nl;pl;pt;ru;sv;tr;zh-CN">
      <InProject>false</InProject>
    </FluentValidationExcludedCultures>
  </ItemGroup>
  <Target Name="FluentValidationRemoveTranslationsAfterBuild" AfterTargets="AfterBuild">
    <RemoveDir Directories="@(FluentValidationExcludedCultures->'$(OutDir)%(Filename)')" />
  </Target>
  <Target Name="FluentValidationRemoveTranslationsAfterPackage" AfterTargets="AfterPublish">
    <RemoveDir Directories="@(FluentValidationExcludedCultures->'$(OutDir)%(Filename)')" />
  </Target>
like image 34
user854301 Avatar answered Nov 15 '22 05:11

user854301