【发布时间】:2011-08-31 13:56:20
【问题描述】:
我有一些文件夹,我想保留在项目中,但不想将其包含在发布中。
这可能吗?
【问题讨论】:
-
对于 .NET Core,请参阅 ASP.NET Core Publish Exclude Folder (or .json files)
标签: c# asp.net .net visual-studio publish
我有一些文件夹,我想保留在项目中,但不想将其包含在发布中。
这可能吗?
【问题讨论】:
标签: c# asp.net .net visual-studio publish
如果它是一个网站项目,您可以排除某些文件夹和/或文件,如下所示(参见元素 ExcludeFoldersFromDeployment 和 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>
【讨论】:
Michael 完全正确,通过编辑 .csproj 文件可以手动排除文件/文件夹的发布。
如果您不想弄乱 .csproj 文件,一种更简单的方法是在 VS 解决方案资源管理器中突出显示文件。在属性面板下,将 build to action 从“content”更改为“none”。
这样,您不必从解决方案中卸载项目,加载 .csproj 并为您添加的每个不需要发布的新文件添加一行,而是通过 3 次鼠标单击实现相同的效果.
(假设您在发布选项卡下设置了“仅发布运行此应用程序所需的文件”)
【讨论】:
您可以在 Web.cspoj 文件中执行“查找和替换”以快速从发布/部署过程中删除特定文件夹
像这样;
<Content Include="Uploads/
到
<None Include="Uploads/
【讨论】:
您可以做的另一种方法是,您可以在 Windows 资源管理器中隐藏不需要发布的文件夹(不是最佳解决方案,但如果您有大量图像仍需要在开发框中,则可以使用)。
【讨论】:
<ItemGroup> <Content Update="Data\CernainFolder\*.*"> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </Content> </ItemGroup>
这应该很好用
【讨论】:
由于问题是用 ASP 标记的,因此没有可以处理的 .proj 文件。在 VS2015 中,还有另一个有用的文件:website.publishproj。而this Asp.Net article on excluding files and folders 提到了.wpp.targets 文件。
所有这些文件都包含<ItemGroup> 元素,其中可能包含<ExcludeFromPackageFolders> 之类的元素。由于这些似乎记录在案的功能,只需使用它们,不要因为黑客或“搞砸”而感到内疚。对我来说,使用该链接的简单说明排除目录和website.publishproj 文件就像一个魅力!
【讨论】: