MS Visual Studio: How to exclude certain Project F

2019-01-13 17:34发布

问题:

I have certain folders which I want to keep in the project but not to include it in publishing.

Is that possible?

回答1:

Michael is totally right, through editing the .csproj file you can manually exclude files/folder from being published.

One easier way if you don't want to mess with the .csproj file is to highlight the file(s) inside the VS solution explorer. Under the properties panel, change build to action from 'content' to 'none'.

This way you don't have to unload the project from the solution, load the .csproj and add a line for each new file you add that doesn't need to be published but instead achieve the same with 3 mouse-clicks.

(assuming you've set the 'Only publish files needed to run this application' under the publishing tab)



回答2:

If it is a web-site project, you may exclude certain folders and/or files as follows (see elements ExcludeFoldersFromDeployment and ExcludeFilesFromDeployment):

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish />
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <ExcludeApp_Data>True</ExcludeApp_Data>
        <publishUrl>D:\YAZILIM\Adopen.2015\PreCompiledWeb</publishUrl>
        <DeleteExistingFiles>True</DeleteExistingFiles>
        <PrecompileBeforePublish>True</PrecompileBeforePublish>
        <EnableUpdateable>True</EnableUpdateable>
        <DebugSymbols>False</DebugSymbols>
        <WDPMergeOption>MergeAllOutputsToASingleAssembly</WDPMergeOption>
        <UseMerge>True</UseMerge>
        <SingleAssemblyName>AdoIntranet</SingleAssemblyName>
        <ExcludeFoldersFromDeployment>customobjects;uploads</ExcludeFoldersFromDeployment> 
        <ExcludeFilesFromDeployment>app.config</ExcludeFilesFromDeployment>
    </PropertyGroup>
</Project>


回答3:

You can do a 'Find & Replace' in the Web.cspoj file to quickly eliminate a particular folder from the publish/deployment process

Like so;

<Content Include="Uploads/

to

<None Include="Uploads/


回答4:

Another way you can do is you can hide folders in windows explorer that are not needed to be get published(not the best solution but works if you have large set of images that still need to be in development box).



回答5:

As the question is tagged with ASP, there is no .proj file to mess with. With VS2015, there is another useful file instead: website.publishproj. And this Asp.Net article on excluding files and folders mentions the .wpp.targets file.

All of these files contain <ItemGroup> elements, that may have elements like <ExcludeFromPackageFolders>. As these seem documented features, just use them and don't feel guilty for hacking or 'messing'. For me, excluding a directory using the simple instructions of that link and the website.publishproj file worked like a charm!