Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude a folder from a project but not from publish?

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?

like image 922
Eric B Avatar asked Jan 23 '17 14:01

Eric B


People also ask

How do I exclude files from a folder?

Go to Start > Settings > Update & Security > Windows Security > Virus & threat protection. Under Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions. Select Add an exclusion, and then select from files, folders, file types, or process.

How do I exclude files from Visual Studio Project?

In Visual Studio, right-click on the file to be excluded from build, choose Properties, Configuration Properties -> General -> Excluded From Build -> Yes -> OK. In Eclipse, right-click on the file to be excluded from build, choose Properties, C/C++ Build -> Excluded from build -> OK.

How do I ignore a folder in Vscode?

To exclude a folder, go to File > Preferences, and search for file. exclude in the search settings. You can add the pattern of the folder you don't want Visual Studio Code to open.


1 Answers

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>
like image 179
Gonzalo Lucero Avatar answered Sep 19 '22 12:09

Gonzalo Lucero