Visual studio 如何在发布期间从预编译中排除cshtml
我在c#web表单项目中有cshtml文件,我希望使用具有以下选项的发布配置文件发布这些文件:Visual studio 如何在发布期间从预编译中排除cshtml,visual-studio,razor,hangfire,postal,Visual Studio,Razor,Hangfire,Postal,我在c#web表单项目中有cshtml文件,我希望使用具有以下选项的发布配置文件发布这些文件: 允许预编译站点可更新=false 我在ASP.net之外使用Postal,因为正在发送的电子邮件来自后台进程。这是使用hangfire,与此非常相似: 问题是,当我不希望cshtml文件被预编译时,它正在被预编译,并且文件的结果内容是: 这是由预编译工具生成的标记文件,不应删除 我需要原始cshtml文件的完整内容,不需要标记内容,但我也希望保留Allow precompiled site to
- 允许预编译站点可更新=false
Allow precompiled site to updateable=false
的设置,以便无法更新所有其他文件
我能看到的唯一方法是让允许预编译站点可更新=true
简而言之,我希望以与将图像文件的构建操作设置为内容时相同的方式部署cshtml
有什么想法吗
编辑:
似乎其他人也有同样的问题:
目前,无法从aspnet_compiler.exe中排除cshtml(或任何其他)文件。这意味着cshtml将与其他所有内容一起进行预编译——我无法找到绕过它的方法 我实现这一点的方法是将“额外”文件作为发布的一部分进行部署,而不是将其作为web项目本身的一部分 本文详细介绍了如何在visual studio项目之外部署额外文件: 在*.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>
文件系统
UAT
任何CPU
假的
C:\Publish\
真的
真的
真的
假的
假的
不要合并
%(RecursiveDir)%(文件名)%(扩展名)
自定义文件;
$(将所有文件复制到SingleFolderForpPackageDependson);
自定义文件;
$(将所有文件复制到SingleFolderForpPackageDependson);
将“额外文件”放在web项目根目录的父目录中名为“额外文件”的文件夹中,它们将在发布期间被复制。在发布后,电子邮件的视图文件再次被原始文件覆盖时,视图可以保持预编译状态
现在,我通过FTP覆盖电子邮件视图文件来手动执行此步骤。如果您没有使用.pubxml,则可以在.csproj文件末尾的
copyallfilestosinglefordeformsdeploy
之后添加Target。在为打包准备好文件之后和打包开始之前,它将数据从任意数量的源复制到打包文件夹:
<Target Name="AdditionalFilesForPackage" AfterTargets="CopyAllFilesToSingleFolderForMsdeploy">
<Message Text="AdditionalFilesForPackage(): MSBuildProjectDirectory -> $(MSBuildProjectDirectory)" />
<Message Text="AdditionalFilesForPackage(): _PackageTempDir -> $(_PackageTempDir)" />
<ItemGroup>
<FolderFiles Include="$(MSBuildProjectDirectory)\FolderName\**\*" />
<OtherCshtmlFiles Include="$(MSBuildProjectDirectory)\OtherCshtml\**\*" />
</ItemGroup>
<Copy SourceFiles="@(FolderFiles)" DestinationFiles="@(FolderFiles->'$(_PackageTempDir)\FolderName\%(RecursiveDir)%(Filename)%(Extension)')" />
<Message Text="AdditionalFilesForPackage(): Done copying FolderName files." />
<Copy SourceFiles="@(OtherCshtmlFiles)" DestinationFiles="@(OtherCshtmlFiles->'$(_PackageTempDir)\OtherCshtml\%(RecursiveDir)%(Filename)%(Extension)')" />
<Message Text="AdditionalFilesForPackage(): Done copying OtherCshtml files." />
</Target>
如果您查看所选答案,您将能够看到如何将其作为发布的一部分进行自动化。