LoginSignup
6
9

More than 5 years have passed since last update.

【ASP.NET MVC】View のビルドチェックを行う方法

Last updated at Posted at 2016-03-02

プロジェクトファイルを編集

プロジェクトのビルド時に 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>

当然ビルドが遅くなるので、必要な時のみ MvcBuildViewstrue とすると良い。

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>

のいずれかを記載すれば、ビルドチェックを行える。

参照

6
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
9