我在我的Web项目中使用Aspnetboilerplate框架。
一切正常,直到我注意到首页访问时我的制作环境非常慢。
做一些研究我发现问题是没有预先编译构建的cshtml视图。所以,在我的vsts构建定义中,我添加了以下内容:
/ p:PrecompileBeforePublish = true / p:UseMerge = true / p:SingleAssemblyName = AppCode
但是现在我在所有的cshtml视图中都出现了以下错误:
Seduca.Web \ obj \ Release \ AspnetCompileMerge \ Source \ App \ Main \ views \ aulas \ index.cshtml(5,0):错误CS0103:名称' IsGranted'在当前上下文中不存在
如果我把它放在每个视图的顶部,则可以工作:
@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("$(BaseIntermediateOutputPath)", "PackageTmp", System.IO.SearchOption.AllDirectories))" />
</ItemGroup>
<Delete Files="@(ExtraWebConfigs)" />
<RemoveDir Directories="@(ExtraPackageTmp)" />
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
错误仅发生在vsts构建中。在本地部署中,(使用发布选项和预编译)可以正常工作。
我已尝试过托管和私人代理。
答案 0 :(得分:-1)
问题似乎是您没有将命名空间添加到正确的Web.config
文件中。 .cshtml
个文件从Views\Web.config
文件获取全局导入的命名空间,而不是根Web.config
文件。
您在根Web.config
文件中的信息是正确的,您只需将其移至Views\Web.config
文件即可。