问题与中间文件有关,但还有另一种解决方案,即在构建视图之前清理这些中间文件。
此解决方案已包含在某些版本的 VS 中,但我只能说我在 VS 2013 Update 5 中遇到了问题。(请参阅下面的“注意”,它可以在此版本中修复,但仅适用于我的特定非标准案例)。
我从错误中借用了解决方案:allowDefinition='MachineToApplication' 在 Visual Studio Connect 上超出应用程序级别。
解决方案包括将这些行包含到.csproj
处理违规中间文件的删除的 Web 应用程序项目(文件)中:
<!--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>
注意:由于某种原因,可能是因为我自己将它包含在项目中,我用于构建视图的构建目标被命名为"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>