Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVCBuildViews工作不正常_C#_Asp.net Mvc_Visual Studio 2010_Msbuild - Fatal编程技术网

C# MVCBuildViews工作不正常

C# MVCBuildViews工作不正常,c#,asp.net-mvc,visual-studio-2010,msbuild,C#,Asp.net Mvc,Visual Studio 2010,Msbuild,因此,我在MVC 3 RTM应用程序上编辑了我的csproj文件,以设置以下属性: <MvcBuildViews>true</MvcBuildViews> true 这将导致我的视图在生成过程中被遵从,并且如果我的视图被破坏,将强制生成错误。这是我所做的唯一更改,但是,当我尝试构建应用程序时,出现以下错误: 在应用程序级别之外使用注册为allowDefinition='MachineToApplication'的节是错误的。此错误可能是由于未在IIS中将虚拟目录配置为

因此,我在MVC 3 RTM应用程序上编辑了我的csproj文件,以设置以下属性:

<MvcBuildViews>true</MvcBuildViews>
true
这将导致我的视图在生成过程中被遵从,并且如果我的视图被破坏,将强制生成错误。这是我所做的唯一更改,但是,当我尝试构建应用程序时,出现以下错误:

在应用程序级别之外使用注册为allowDefinition='MachineToApplication'的节是错误的。此错误可能是由于未在IIS中将虚拟目录配置为应用程序造成的

如果我改回false,项目将成功编译并运行

以下是在csproj文件中配置的生成任务(这些任务从未被手动编辑,它们是由Visual Studio 2010添加的)


-->

我是不是遗漏了什么?如何正确配置MVC 3/Visual Studio 2010以在构建时验证我的视图?

几天前我遇到了这个问题,我通过删除obj/Debug文件夹解决了这个问题。清洁项目也很有效。不过,我不知道问题的原因


有关更持久的解决方案,请参阅。

当您遇到此错误时,您的obj文件夹中是否有另一个web.config文件?如果您正在使用MSDeploy,这可能会有所帮助:,如果没有,则可能是您正在运行的某个工具正在生成另一个web.config。

当obj文件夹中存在web项目输出(模板化的web.config或临时发布文件)时,会出现此问题。使用的ASP.NET编译器不够聪明,无法忽略obj文件夹中的内容,因此它会抛出错误

另一个修复方法是在调用之前取消发布输出,您可以完全排除obj文件夹。显然,
任务没有exclude参数,但是如果您切换到直接调用aspnet\u compiler.exe,您可以像这样排除obj:

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <Exec Command="$(MSBuildFrameworkToolsPath)aspnet_compiler.exe -v temp -p $(WebProjectOutputDir) -x $(BaseIntermediateOutputPath)"/>
</Target>
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" /> <!--add this line-->
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

这对我来说很有用。或者,您可以使用配置指定条件

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
<Target Name="AfterBuild" Condition="'$(Configuration)'!='Debug'">
  <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>

即使MvcBuildViews设置为“true”,编译时视图检查的问题也在以下MSDN博客中得到了很好的解释:

您可以通过直接编辑.csproj文件进行修复:

<PropertyGroup>
   <MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>

 <Target Name="BuildViews" Condition="'$(MvcBuildViews)'=='true'" AfterTargets="Build">
   <Message Importance="normal" Text="Precompiling views" />
   <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
 </Target>

真的

一个简单的解决方案是根据这里的其他答案编译而成的

您只需删除整个
/obj
文件夹,如下所示:

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <Exec Command="$(MSBuildFrameworkToolsPath)aspnet_compiler.exe -v temp -p $(WebProjectOutputDir) -x $(BaseIntermediateOutputPath)"/>
</Target>
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" /> <!--add this line-->
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>


我尝试过这个方法,但可惜没有成功。我将尝试下面的一些其他解决方案,以期成功。这是可行的,但每次重新启动VS2010时,您都必须再次删除该文件夹。请参阅下面的Joe Cartano的答案,以获得永久解决方案:
true
在您的csproj文件中可能会导致在生成服务器上出现这种情况(设置告诉visual studio编译视图)是的,谢谢。我把它添加到我的.proj文件中:
。\bin
所以现在obj文件夹处于解决方案级别,构建问题消失了!!!要保存以下链接,可以将
元素直接放置在项目文件中
的下面。将临时目录命名为“obj”而不是“bin”可能更为正确,但这并不重要。@JohnBubriski如果从注释中复制代码,可能会出现一些奇怪的unicode(我猜想)问题,导致开始标记与结束标记不匹配,即使它们看起来相同。结束标记在“Path”中的“a”和“t”之间有一些不可见的字符。您的web.config中定义了一些无效的部分。不幸的是,错误消息没有提供任何细节。你在web.config中有什么可疑的东西吗?这个解决方案对我也很有用。运行VS2013和MVC5,或者如果您希望简单地删除整个obj\Debug(或obj\Release)文件夹,只需在前面添加以下一行代码即可:通常,这是Nick Canzoneri接受的答案的实现。
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" /> <!--add this line-->
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>