繁体   English   中英

MS Visual Studio:如何从发布中排除某些项目文件夹?

[英]MS Visual Studio: How to exclude certain Project Folders from publishing?

我有某些文件夹,我想保留在项目中,但不想将其包含在发布中。

那可能吗?

Michael是完全正确的,通过编辑 .csproj 文件,您可以手动排除文件/文件夹的发布。

如果您不想弄乱 .csproj 文件,一种更简单的方法是在 VS 解决方案资源管理器中突出显示文件。 在属性面板下,将 build to action 从“content”更改为“none”。

这样,您不必从解决方案中卸载项目,加载 .csproj 并为您添加的每个新文件添加一行,该文件不需要发布,而是通过 3 次鼠标单击实现相同的效果。

(假设您在发布选项卡下设置了“仅发布运行此应用程序所需的文件”)

如果它是一个网站项目,您可以排除某些文件夹和/或文件,如下所示(请参阅元素ExcludeFoldersFromDeploymentExcludeFilesFromDeployment ):

<?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>

您可以在 Web.cspoj 文件中执行“查找和替换”,以快速从发布/部署过程中删除特定文件夹

像这样;

<Content Include="Uploads/

<None Include="Uploads/

您可以做的另一种方法是您可以隐藏 windows 资源管理器中不需要发布的文件夹(不是最佳解决方案,但如果您有大量图像仍需要在开发框中,则可以使用)。

  • 卸载项目,
  • 右键单击编辑 *.csproj,
  • 添加这个:
 <ItemGroup> <Content Update="Data\CernainFolder\*.*"> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </Content> </ItemGroup>
  • 重新加载项目。

这应该很好用

由于问题是用 ASP 标记的,因此没有.proj文件可以处理。 在 VS2015 中,还有另一个有用的文件: website.publishproj 这篇关于排除文件和文件夹的 Asp.Net 文章提到了.wpp.targets文件。

所有这些文件都包含<ItemGroup>元素,其中可能包含<ExcludeFromPackageFolders>等元素。 由于这些似乎记录在案的功能,只需使用它们,不要因为黑客或“搞砸”而感到内疚。 对我来说,使用该链接的简单说明排除目录和website.publishproj文件就像一个魅力!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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