プロジェクトファイルを編集
プロジェクトのビルド時に View のビルドチェックを行うには、プロジェクトファイル *.csproj
をエディタで開き、下記タグを埋め込めば OK 。
*.csproj
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<PropertyGroup>
...
<!-- これを埋め込む -->
<MvcBuildViews>true</MvcBuildViews>
...
</PropertyGroup>
...
<!-- これも埋め込む -->
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
</Project>
当然ビルドが遅くなるので、必要な時のみ MvcBuildViews
を true
とすると良い。
EF 使用時のエラーへの対処
プロジェクト内で Entity Framework を使用していると
型 'System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider' を読み込めませんでした。 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config 132
や
Could not load type 'System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider'. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config 129
等と出力されるので、その際には web.config
に
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<system.web>
...
<compilation debug="true" targetFramework="4.5.2">
...
<!-- edmx ファイルを事前ビルド(MvcBuildViews)する際に必要 -->
<!--<assemblies>
<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>-->
<!-- edmx ファイルを事前ビルド(MvcBuildViews)から除外する際に必要 -->
<buildProviders>
<remove extension=".edmx"/>
</buildProviders>
...
</compilation>
...
<system.web>
...
</configuration>
のいずれかを記載すれば、ビルドチェックを行える。