gpt4 book ai didi

asp.net-mvc - cshtml 无法在生产中构建 (vsts)

转载 作者:行者123 更新时间:2023-12-05 08:08:34 25 4
gpt4 key购买 nike

我在我的 Web 项目中使用 Aspnetboilerplate 框架。

一切正常,直到我注意到我的生产环境在访问第一页时速度非常慢。

做一些研究后我发现问题是在构建时没有预编译 cshtml View 。因此,在我的 vsts 构建定义中,我添加了以下内容:

/p:PrecompileBeforePublish=true /p:UseMerge=true /p:SingleAssemblyName=AppCode

但现在我的所有 cshtml View 都出现以下错误:

Seduca.Web\obj\Release\AspnetCompileMerge\Source\App\Main\views\aulas\index.cshtml(5,0): Error CS0103: The name 'IsGranted' does not exist in the current context

如果我把它放在每个 View 的顶部就可以工作:

@inherits Seduca.Web.Views.SeducaWebViewPageBase

但看起来我的文件 (web.config) 被忽略了。

我的 .csproj 看起来像这样:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<MvcBuildViews>true</MvcBuildViews>
<LangVersion>6</LangVersion>
</PropertyGroup>
...
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<ItemGroup>
<ExtraWebConfigs Include="$(BaseIntermediateOutputPath)\**\web.config" />
<ExtraPackageTmp Include="$([System.IO.Directory]::GetDirectories(&quot;$(BaseIntermediateOutputPath)&quot;, &quot;PackageTmp&quot;, System.IO.SearchOption.AllDirectories))" />
</ItemGroup>
<Delete Files="@(ExtraWebConfigs)" />
<RemoveDir Directories="@(ExtraPackageTmp)" />
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

还有 web.config: enter image description here

该错误仅发生在 vsts 构建中。在本地部署中,(使用发布选项和预编译)它可以工作。

我尝试过在 vsts 上使用托管代理和私有(private)代理。

最佳答案

问题似乎是您没有将 namespace 添加到正确的 Web.config 文件中。 .cshtml 文件从 Views\Web.config 文件而不是根 Web.config 文件获取全局导入的命名空间。

Web.config 文件中的信息是正确的,只需将其移动到 Views\Web.config 文件即可。

关于asp.net-mvc - cshtml 无法在生产中构建 (vsts),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48208661/

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