问题与中间文件有关,但是还有另一种解决方案,其中包括在建立视图之前清理那些中间文件。
该解决方案已被列入某些版本的VS,但我只能说,我在VS有问题2013更新5.(参见“小心”下面,它可以被固定在这个版本,但不只是在我的特殊工作非标准案例)。
我从错误中借了解决方法:allowDefinition ='MachineToApplication',超出了Visual Studio Connect上的应用程序级别。
解决方案包括将这些行包含在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>
当心:出于某种原因,可能是因为我自己将其包括在项目"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>