gpt4 book ai didi

visual-studio - 如何在发布期间从预编译中排除 cshtml

转载 作者:行者123 更新时间:2023-12-04 02:21:16 24 4
gpt4 key购买 nike

我在 c# web 表单项目中有 cshtml 文件,我想使用具有以下选项的发布配置文件进行发布:

  • 允许预编译站点可更新 = false

  • 我在 ASP.net 之外使用 Postal http://aboutcode.net/postal/outside-aspnet.html因为正在发送的电子邮件来自后台进程。这是使用hangfire,与此非常相似: http://docs.hangfire.io/en/latest/tutorials/send-email.html

    问题是当我不希望 cshtml 文件被预编译并且文件的结果内容是:

    This is a marker file generated by the precompilation tool, and should not be deleted!



    我需要原始 cshtml 文件的全部内容,不需要标记内容,但我也想保留 Allow precompiled site to be updateable = false 的设置所以所有其他文件都无法更新。

    我能看到的唯一方法是让 Allow precompiled site to be updateable = true
    简而言之,我想以与图像文件的构建操作设置为内容相同的方式部署 cshtml。

    有任何想法吗?

    编辑:
    似乎其他人有完全相同的问题:

    Is there a way to exclude certain .cshtm files, or an entire folder, from the 'precompile' option so that the .cshtml files can be used outside MVC?

    最佳答案

    目前,无法从 aspnet_compiler.exe 中排除 cshtml(或任何其他)文件。这意味着 cshtml 将与其他所有内容一起预编译 - 我无法找到绕过它的方法。

    我让它工作的方式是将“额外”文件部署为发布的一部分,而不是让它们成为 Web 项目本身的一部分。

    本文详细解释了如何在 Visual Studio 项目之外部署额外文件:

    ASP.NET Web Deployment using Visual Studio: Deploying Extra Files

    在你的 *.pubxml

    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>UAT</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>C:\Publish\</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>False</EnableUpdateable>
    <DebugSymbols>False</DebugSymbols>
    <WDPMergeOption>DonotMerge</WDPMergeOption>
    </PropertyGroup>
    <Target Name="CustomCollectFiles">
    <ItemGroup>
    <_CustomFiles Include="..\ExtraFiles\**\*" />
    <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
    <DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
    </ItemGroup>
    </Target>
    <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>
    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
    </PropertyGroup>
    </Project>

    将“额外文件”放在 Web 项目根目录的父目录中名为“ExtraFiles”的文件夹中,它们将在发布期间复制。

    关于visual-studio - 如何在发布期间从预编译中排除 cshtml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29160227/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com