This error is unusually due to web.config inheritance where two web.config files exist in different folders within the same IIS application.
error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level, when adding <hostingEnvironment shadowCopyBinAssemblies="false" /> in web.config file.
I've an azure cloud service web role project. In the csproj file I have the pre-compilation steps to basically pre-compile the asp.net application and generate app_*.dll's
. Now I've to add <hostingEnvironment shadowCopyBinAssemblies="false" />
in the web.config file but the build starts failing with error
C:\Users\sharmapulkit\source\repos\AI-AzureCIP\src\ccm\api\CCMApiCloudService\CCMApiWebRole\obj\Websites\bin\web.config(745): error ASPCONFIG: 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.
Below is the csproj file, I've removed the package reference / project reference related sections
<Project Sdk="MSBuild.SDK.SystemWeb/4.0.88" TreatAsLocalProperty="MvcBuildViews;_CreatePackage">
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3A51F1D2-AD07-4614-81A1-451FCDDBDB8F}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.CE.CIP.CCMApiWebRole</RootNamespace>
<AssemblyName>Microsoft.CE.CIP.CCMApiWebRole</AssemblyName>
<TargetFramework>net472</TargetFramework>
<UseIISExpress>true</UseIISExpress>
<EnableWebFormsDefaultItems>false</EnableWebFormsDefaultItems>
<CodeAnalysisRuleSet>$(SRCROOT)\Libraries\RuleSets\AIInfraEng.ruleset</CodeAnalysisRuleSet>
<OutputPath>$(BinariesBuildTypeArchDirectory)\$(AssemblyName)</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<WebsitePath>$(BaseIntermediateOutputPath)Websites</WebsitePath>
<CompiledSitesPath>$(BinariesBuildTypeArchDirectory)\WebRole\$(TargetFramework)\CompiledSites</CompiledSitesPath>
<CompiledWebsitePath>$(CompiledSitesPath)\WebRole</CompiledWebsitePath>
<CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<GeneratedBindingRedirectsAction>Overwrite</GeneratedBindingRedirectsAction>
<RunCodeAnalysis>false</RunCodeAnalysis>
<IISExpressSSLPort></IISExpressSSLPort>
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<TargetFrameworkProfile />
<Use64BitIISExpress>true</Use64BitIISExpress>
<DeployOnBuild>true</DeployOnBuild>
<PrecompileBeforePublish>false</PrecompileBeforePublish>
<EnableUpdateable>false</EnableUpdateable>
<WDPMergeOption>DonotMerge</WDPMergeOption>
<MvcBuildViews>false</MvcBuildViews>
<TransformWebConfigEnabled>true</TransformWebConfigEnabled>
<_CreatePackage>false</_CreatePackage>
</PropertyGroup>
<Target Name="CopyFiles" AfterTargets="Build" BeforeTargets="PrepareToPrecompileWeb">
<CreateItem Include="$(TargetDir)
**
*">
<Output ItemName="MyBuiltFiles" TaskParameter="Include" />
</CreateItem>
<Copy SourceFiles="@(MyBuiltFiles)" DestinationFiles="@(MyBuiltFiles->'$(ProjectDir)\bin%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
<Target Name="PrepareToPrecompileWeb" AfterTargets="CopyFiles" BeforeTargets="BeforePrecompileWeb">
<RemoveDir Directories="$(WebsitePath)" />
<CreateItem Include="$(TargetDir)
**" Exclude="$(TargetDir)
*\app_global.asax.dll;$(TargetDir)
**.compiled;$(CompiledSitesPath)
**.*">
<Output ItemName="WebBuiltFiles" TaskParameter="Include" />
</CreateItem>
<Copy SourceFiles="@(WebBuiltFiles)" DestinationFiles="@(WebBuiltFiles->'$(WebsitePath)\bin%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
<ItemGroup>
<WebsiteRoot Include="Global.asax" />
<WebsiteSvc Include="*.svc" />
<WebsiteConfig Include="Web.config" />
</ItemGroup>
<Copy SourceFiles="@(WebsiteRoot)" DestinationFolder="$(WebsitePath)" />
<Copy SourceFiles="@(WebsiteSvc)" DestinationFolder="$(WebsitePath)" />
<Copy SourceFiles="@(WebsiteConfig)" DestinationFolder="$(WebsitePath)" />
</Target>
<Target Name="BeforePrecompileWeb" AfterTargets="PrepareToPrecompileWeb" Condition="'$(BuildingInsideVisualStudio)' != 'true'">
<Exec Command="attrib +H "$(WebsitePath)\bin*.h" /S" />
<Exec Command="attrib +H "$(WebsitePath)\bin\web.config" /S" />
<!-- <Exec Command="attrib +H "$(ProjectDir)\obj\Debug\Package\PackageTmp\bin*.h" /S"/>
<Exec Command="attrib +H "$(ProjectDir)\bin*.h" /S" /> -->
</Target>
<Target Name="PrecompileWeb" AfterTargets="BeforePrecompileWeb" Condition="'$(BuildingInsideVisualStudio)' != 'true'">
<AspNetCompiler ToolPath="$(MSBuildFrameworkToolsPath64)" PhysicalPath="$(WebsitePath)" VirtualPath="/" TargetPath="$(CompiledWebsitePath)" Force="true" FixedNames="true" />
<!-- The following will catch and fail build if app_.dll is not generated as expected. Add similar check for app_web_.dll if needed -->
<ItemGroup>
<AspNetDLLs Include="$(CompiledWebsitePath)\bin\app_*.dll" />
</ItemGroup>
<Error Text="aspnetcompiler task did not generate compiled app_global or app_web assemblies" Condition="@(AspNetDLLs->Count()) == '0'" />
<ItemGroup>
<CompiledAsax Include="$(CompiledWebsitePath)\bin\app_global.asax.dll" /> <CompiledSvc Include="$(CompiledWebsitePath)\bin\*.compiled" /> <CompiledAppConfig Include="$(CompiledWebsitePath)\PrecompiledApp.config" />
</ItemGroup>
<Copy SourceFiles="@(CompiledAsax)" DestinationFolder="$(TargetDir)" />
<Copy SourceFiles="@(CompiledSvc)" DestinationFolder="$(TargetDir)" />
<Copy SourceFiles="@(CompiledAppConfig)" DestinationFolder="$(TargetDir)" />
</Target>
<Target Name="AfterPrecompileWeb" AfterTargets="PrecompileWeb" Condition="'$(BuildingInsideVisualStudio)' != 'true'">
<Exec Command="attrib -H "$(WebsitePath)\bin*.h" /S" />
<Exec Command="attrib -H "$(WebsitePath)\bin\web.config" /S" />
<!-- <Exec Command="attrib -H "$(ProjectDir)\obj\Debug\Package\PackageTmp\bin*.h" /S" />
<Exec Command="attrib -H "$(ProjectDir)\bin*.h" /S" /> -->
</Target>
</Project>