简体   繁体   中英

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?

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM