allowDefinition=“MachineToApplication”从 VS2010 发布时出错(但仅在之前的构建之后)

发布于 2024-08-27 07:33:17 字数 382 浏览 6 评论 0原文

我可以在本地计算机上毫无问题地运行我的 Asp.Net MVC 2 应用程序。只需运行/调试。

但如果我已经构建了它,我就无法发布它!我必须清理解决方案并再次发布。我知道这不是系统关键,但这确实很烦人。 “一键发布”不是“清理解决方案然后一键发布”

具体错误如下:

错误11 使用a是错误的 部分注册为 允许定义='机器到应用程序' 超出应用程序级别。这个错误 可能是虚拟目录引起的 未配置为应用程序 在 IIS 中。

我怀疑这与 Views 文件夹中的 Web.Config 有关,但为什么只有在我之前构建过一次之后。需要注意的是,该应用程序一旦发布就可以正常工作。

I can run my Asp.Net MVC 2 application without an issue on my local computer. Just Run / Debug.

But if I have already built it, I can't publish it! I have to clean the solution and publish it again. I know this is not system critical, but it's really annoying. "One Click Publish" is not "Clean solution and then One click publish"

The exact error is as follows:

Error 11 It is an error to use a
section registered as
allowDefinition='MachineToApplication'
beyond application level. This error
can be caused by a virtual directory
not being configured as an application
in IIS.

I suspect it's something to do with the Web.Config in the Views folder, but then why only after I build once previously. And just to note, the app works fine once published.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

猫卆 2024-09-03 07:33:18

该问题与中间文件有关,但还有另一种解决方案,即在构建视图之前清理这些中间文件。

这个解决方案已经包含在VS的某些版本中,但我只能说我在VS 2013 Update 5中遇到了这个问题。(参见下面的“注意”,它可以在这个版本中修复,但仅在我的特定非标准情况下不起作用)。

我从 错误:allowDefinition= 借用了解决方案Visual Studio Connect 上的“MachineToApplication”超出了应用程序级别。

解决方案包括将这些行包含到 Web 应用程序项目(.csproj 文件)中,以处理删除问题的中间文件:

<!--Deal with http://connect.microsoft.com/VisualStudio/feedback/details/779737/error-allowdefinition-machinetoapplication-beyond-application-level, 
we will need to clean up our temp folder before MVC project starts the pre-compile-->
<PropertyGroup>
    <_EnableCleanOnBuildForMvcViews Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='' ">true</_EnableCleanOnBuildForMvcViews>
</PropertyGroup>
<Target Name="CleanupForBuildMvcViews" Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='true' and '$(MVCBuildViews)'=='true' " BeforeTargets="MvcBuildViews">
    <ItemGroup>
     <_PublishTempFolderNamesToCleanup Include="Database;TransformWebConfig;CSAutoParameterize;InsertAdditionalCS;ProfileTransformWebConfig;Package;AspnetCompileMerge" />
    </ItemGroup>
    <!--Force msbuild to expand all the wildcard characters so to get real file paths-->
    <CreateItem Include="@(_PublishTempFolderNamesToCleanup->'$(BaseIntermediateOutputPath)**\%(identity)\**\*')">
     <Output TaskParameter="Include" ItemName="_EvaluatedPublishTempFolderNamesToCleanup" />
    </CreateItem>
    <Delete Files="@(_EvaluatedPublishTempFolderNamesToCleanup)" />
</Target>

< strong>注意:由于某种原因,可能是因为我自己将其包含在项目中,我用于构建视图的构建目标被命名为 "BuildViews",而不是 "MvcBuildViews",所以我必须相应地修改 BeforeTargets 属性。我还通过删除 PropertyGroup 并简化条件来简化目标,如下所示:

  <Target Name="CleanupForBuildMvcViews" Condition="'$(MVCBuildViews)'=='true' " BeforeTargets="BuildViews">
    <ItemGroup>
     <_PublishTempFolderNamesToCleanup Include="Database;TransformWebConfig;CSAutoParameterize;InsertAdditionalCS;ProfileTransformWebConfig;Package;AspnetCompileMerge" />
    </ItemGroup>
    <!--Force msbuild to expand all the wildcard characters so to get real file paths-->
    <CreateItem Include="@(_PublishTempFolderNamesToCleanup->'$(BaseIntermediateOutputPath)**\%(identity)\**\*')">
     <Output TaskParameter="Include" ItemName="_EvaluatedPublishTempFolderNamesToCleanup" />
    </CreateItem>
    <Delete Files="@(_EvaluatedPublishTempFolderNamesToCleanup)" />
  </Target>

The problem has to do with the intermediate files, but there is another solution which consist in cleaning up those intermediate files before builnding the views.

This solution has been included in some version of VS, but I can only say that I had the problem in VS 2013 Update 5. (See the "Beware" below, it could be fixed in this version, but not working only in my particular non-standard case).

I borrowed the soltuion from Error: allowDefinition='MachineToApplication' beyond application level on Visual Studio Connect.

The solution consist in including these lines to the web application project (.csproj file) which handle the deletion of the offedning intermediate files:

<!--Deal with http://connect.microsoft.com/VisualStudio/feedback/details/779737/error-allowdefinition-machinetoapplication-beyond-application-level, 
we will need to clean up our temp folder before MVC project starts the pre-compile-->
<PropertyGroup>
    <_EnableCleanOnBuildForMvcViews Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='' ">true</_EnableCleanOnBuildForMvcViews>
</PropertyGroup>
<Target Name="CleanupForBuildMvcViews" Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='true' and '$(MVCBuildViews)'=='true' " BeforeTargets="MvcBuildViews">
    <ItemGroup>
     <_PublishTempFolderNamesToCleanup Include="Database;TransformWebConfig;CSAutoParameterize;InsertAdditionalCS;ProfileTransformWebConfig;Package;AspnetCompileMerge" />
    </ItemGroup>
    <!--Force msbuild to expand all the wildcard characters so to get real file paths-->
    <CreateItem Include="@(_PublishTempFolderNamesToCleanup->'$(BaseIntermediateOutputPath)**\%(identity)\**\*')">
     <Output TaskParameter="Include" ItemName="_EvaluatedPublishTempFolderNamesToCleanup" />
    </CreateItem>
    <Delete Files="@(_EvaluatedPublishTempFolderNamesToCleanup)" />
</Target>

Beware: for some reason, probably because I included it myself in the project, my build target for building the views was named "BuildViews", instead of "MvcBuildViews", so I had to modify the BeforeTargets attribute accordingly. I also simplified the target, by removing the PropertyGroup and simplifying the condition, like this:

  <Target Name="CleanupForBuildMvcViews" Condition="'$(MVCBuildViews)'=='true' " BeforeTargets="BuildViews">
    <ItemGroup>
     <_PublishTempFolderNamesToCleanup Include="Database;TransformWebConfig;CSAutoParameterize;InsertAdditionalCS;ProfileTransformWebConfig;Package;AspnetCompileMerge" />
    </ItemGroup>
    <!--Force msbuild to expand all the wildcard characters so to get real file paths-->
    <CreateItem Include="@(_PublishTempFolderNamesToCleanup->'$(BaseIntermediateOutputPath)**\%(identity)\**\*')">
     <Output TaskParameter="Include" ItemName="_EvaluatedPublishTempFolderNamesToCleanup" />
    </CreateItem>
    <Delete Files="@(_EvaluatedPublishTempFolderNamesToCleanup)" />
  </Target>
℉絮湮 2024-09-03 07:33:18

就我而言,我发现当我将 MvcBuildViews 和 PrecompileDuringPublish 都设置为 true 时,这就是导致此问题的原因。

所以我删除了 PrecompileDuringPublish,该解决方案对我有用,从那以后我就没有遇到过这个问题。

输入图片此处描述

In my case i saw that when i have MvcBuildViews and PrecompileDuringPublish as both true - was what was causing this issue.

So i removed the PrecompileDuringPublish and that solution worked for me and i have not faced this problem since.

enter image description here

忆沫 2024-09-03 07:33:17

我的 MVC 应用程序也有同样的问题。这很令人沮丧,因为我仍然希望检查我的视图,所以我不想关闭 MvcBuildViews

幸运的是我遇到了 帖子 这给了我答案。将 MvcBuildViews 保持为 true,然后您可以在项目文件下面添加以下行:

<BaseIntermediateOutputPath>[SomeKnownLocationIHaveAccessTo]</BaseIntermediateOutputPath>

并使该文件夹不在您的项目文件夹中。对我有用。这不是一个完美的解决方案,但目前来说是好的。确保从项目文件夹中删除 package 文件夹(位于 obj\Debug 和/或 obj\Release 文件夹内),否则您会会不断收到错误。

FWIW,MS了解此错误...

i had the same problem with my MVC apps. it was frustrating because i still wanted my views to be checked, so i didn't want to turn off MvcBuildViews

luckily i came across a post which gave me the answer. keep the MvcBuildViews as true, then you can add the following line underneath in your project file:

<BaseIntermediateOutputPath>[SomeKnownLocationIHaveAccessTo]</BaseIntermediateOutputPath>

And make that folder not in your project's folder. Works for me. It's not a perfect solution, but it's good for the moment. Make sure you remove the package folder (located inside the obj\Debug and/or obj\Release folder) from your project folder otherwise you'll keep getting the error.

FWIW, MS know about this error...

浴红衣 2024-09-03 07:33:17

我删除了 obj/Debug 文件夹中的所有内容,并修复了此错误。这允许我保留

<MvcBuildViews>true</MvcBuildViews>

项目文件中的选项(这与 T4MVC T4 模板一起派上用场)。

编辑:
只需使用“Build”->“Build”即可轻松实现这一点。 “重建解决方案”菜单(因为重建实际上所做的是清除 obj/Debug 文件夹,然后构建解决方案)。

I deleted everything out of my obj/Debug folder and it fixed this error. This allowed me to leave in the

<MvcBuildViews>true</MvcBuildViews>

option in my project file (which comes in handy with the T4MVC T4 template).

Edit:
This can be achieved much easier by simply using the "Build" -> "Rebuild Solution" menu (because what rebuild actually does is clear the obj/Debug folder and then build solution).

暮凉 2024-09-03 07:33:17

我在 MS Connect 页面查看此错误。在运行 AspNetCompiler 之前,它会清除项目下的所有 obj 和临时文件(所有配置)。

修改MvcBuildViews目标
您的项目文件,以便它取决于
关于清理的目标
Visual Studio 具有的打包文件
创建的。这些目标包含在
网络应用程序项目
自动。

所有打包文件将被删除
每次 MvcBuildViews
目标执行。

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'" DependsOnTargets="CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(MSBuildProjectDirectory)" />
</Target>

I'm using this workaround on the MS Connect page for this error. It cleans all obj and temp files under your project (all configurations) before running AspNetCompiler.

Modify the MvcBuildViews target in
your project file so that it depends
on the targets that clean up the
packaging files that Visual Studio has
created. These targets are included in
web application projects
automatically.

All packaging files will be deleted
every time that the MvcBuildViews
target executes.

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'" DependsOnTargets="CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(MSBuildProjectDirectory)" />
</Target>
梦醒时光 2024-09-03 07:33:17

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

另一个修复方法是在调用之前取消发布输出。打开 .csproj 并将其更改

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

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

:这将删除 \obj 下的所有 web.config,以及 \obj 下的所有 PackageTmp 文件夹。

This problem occurs when there is web project output (templated web.config or temporary publish files) in the obj folder. The ASP.NET compiler used isn't smart enough to ignore stuff in the obj folder, so it throws errors instead.

Another fix is to nuke the publish output right before calling <AspNetCompiler>. Open your .csproj and change this:

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

to this:

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

That will delete all web.configs under \obj, as well as all PackageTmp folders under \obj.

愛放△進行李 2024-09-03 07:33:17

如果您使用的是 Web Publish,则可以设置 MvcBuildViews=falsePrecompileBeforePublish=true,这会在复制到临时文件夹后(紧接着发布/打包之前)进行预编译。

注意:PrecompileBeforePublish 仅受“新”Web 发布管道堆栈(VS2010 SP1 + Azure SDK 或 VS2012 RTM)支持。如果您使用的是 VS2010 RTM,则需要使用其中一种替代方法。

If you are using Web Publish, you can set MvcBuildViews=false and PrecompileBeforePublish=true, which precompiles after the copy to the temporary folder (immediately before publish/package).

NOTE: PrecompileBeforePublish is only supported by the "new" Web Publishing Pipeline stack (VS2010 SP1 + Azure SDK or VS2012 RTM). If you're using VS2010 RTM, you'll need use one of the alternative methods.

白云悠悠 2024-09-03 07:33:17

关于jrummell的解决方案,设置:


DependsOnTargets =“CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;”

可以在 VS 2010 中运行,但不能在 VS 2012 中运行。 2012 年你必须输入:


DependsOnTargets =“CleanWebsitesPackage;CleanWebsitesWPPAllFilesInSingleFolder;CleanWebPublishPipelineIntermediateOutput”
来源

VS 2010:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets

VS 2012:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets

Regarding the solution by jrummell, the setting:


DependsOnTargets="CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;"

It works in VS 2010, but not in VS 2012. In 2012 you have to put:


DependsOnTargets="CleanWebsitesPackage;CleanWebsitesWPPAllFilesInSingleFolder;CleanWebPublishPipelineIntermediateOutput"

Source:

VS 2010:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets

VS 2012:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets

甜味拾荒者 2024-09-03 07:33:17

我知道这个问题已经得到解答,但我只是想添加一些我发现的有趣的东西。

我已在项目中将“MvcBuildViews”设置为 false,删除了所有 bin 和 obj 文件夹,但仍然收到错误。我发现有一个“.csproj.user”文件仍然将“MvcBuildViews”设置为 true。

我删除了“.csproj.user”文件,然后一切正常。

因此,如果您要更改 csproj 文件,请确保同时更改或删除“.csproj.user”文件。

I know this has been answered but I just wanted to add something interesting I found.

I had set the "MvcBuildViews" to false in the project, deleted all bin and obj folders and I was still getting the error. I found that there was a ".csproj.user" file that still had "MvcBuildViews" set to true.

I deleted the ".csproj.user" file and then it all worked.

So make sure if you are changing your csproj file that you either change or delete the ".csproj.user" file also.

昔梦 2024-09-03 07:33:17

我也遇到了这个问题,所以我在项目属性中创建了一个预构建事件来清理输出目录(${projectPath}\bin,${projectPath}\obj\${ConfigurationName} )。在另一个项目中,即使进行了清洁活动,我也遇到了这个错误。在第二个项目中,我正在编译项目文件中列出的视图:

<MvcBuildViews>true</MvcBuildViews>

我将 true 更改为 false,并且它不再抱怨该错误,但仍然正确运行。我不会声称我确切知道是什么导致了第二个错误,但至少它暂时让我继续前进。

I had this problem as well, so I created a Pre-Build Event in the project properties to Clean the output directories(${projectPath}\bin,${projectPath}\obj\${ConfigurationName}). On another project I was also getting this error, even with the cleaning event in place. On the second project I was compiling the views as listed in the project file:

<MvcBuildViews>true</MvcBuildViews>

I changed the true to false, and it no longer complained about that error, but still ran correctly. I won't claim I know exactly what was causing the second error, but at least it got me moving forward for the time being.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文