Home cshtml failed to build in production (vsts)
Reply: 1

cshtml failed to build in production (vsts)

Munir
1#
Munir Published in 2018-01-11 13:52:21Z

I'm using Aspnetboilerplate framework in my Web project.

Everything was working until I noticed that my production environment was very slow on first page access.

Doing some researchs I discovered that the problem was to not pre compile cshtml views on build. So, in my vsts build definition I added the follow:

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

But now I'm getting the follow error on all my cshtml views:

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

Works if I put this on top of each view:

@inherits Seduca.Web.Views.SeducaWebViewPageBase

but it looks like my file (web.config) is being ignored.

My .csproj looks like this:

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

And the web.config:

The error only happens in vsts build. In local deploy, (with release option and precompile) it works.

I've tried with hosted and private agents on vsts.

NightOwl888
2#
NightOwl888 Reply to 2018-01-16 04:48:34Z

The issue appears to be that you are not adding the namespaces to the correct Web.config file. .cshtml files get their globally imported namespaces from the Views\Web.config file, not the root Web.config file.

The information you have in the root Web.config file is correct, you just need to move it to the Views\Web.config file.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.320076 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO