如何从项目中排除文件夹,而不从发布中排除文件夹? [英] How do I exclude a folder from a project but not from publish?

查看:364
本文介绍了如何从项目中排除文件夹,而不从发布中排除文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将asp.net核心项目迁移到VS2017 RC,该项目现在支持从项目中排除文件的功能.我排除了两个文件夹,这两个文件夹将这些行添加到了我的csproj文件中:

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 csproj file:

<ItemGroup>
  <Content Remove="wwwroot\dist\**" />
  <Content Remove="wwwroot\lib\**" />
</ItemGroup>

这很好用,除了现在不再发布那些文件了.如何将这些文件夹从项目中排除,但仍将其包含在发布中?

This works great, except now those files don't get published anymore. How do I exclude these folders from the project but still include them on publish?

推荐答案

从dotnet新的spa模板中获取的以下msbuild项帮助我实现了我认为的目标:

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-&gt;'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
            <RelativePath>%(DistFiles.Identity)</RelativePath>
            <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        </ResolvedFileToPublish>
    </ItemGroup>
</Target>

这篇关于如何从项目中排除文件夹,而不从发布中排除文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆