R – aspnet_compiler fails when using App_Browsers folder with Web Deployment Project

asp.netaspnet-compiler

When Compiling my Web Deployment Project which references a Asp.Net project with a App_Browsers folder I get the following compilation error:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -v /[PROJECTNAME].csproj -p "[FILEPATH]" -u -f -d .\TempBuildDir\
ASPNETCOMPILER : error ASPRUNTIME: Object reference not set to an instance of an object.

If I remove the App_Browsers folder everything works perfectly.

Any help would be appreciated.

Best Answer

Ok, finally found a solution.

As stated the aspnet compiler crashes when including the App_Browsers folder. So to avoid that, I have excluded the folder from the build and put in an "after build" action which copies the folder to the destination. This is done by adding the following lines of code to the deployment project file:

  <ItemGroup>
      <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\App_Browsers\**\*.*"/>
      <MySourceFiles Include="$(SourceWebPhysicalPath)\App_Browsers\**\*.*"/>
  </ItemGroup>
  <Target Name="AfterBuild">
      <MakeDir Directories="$(OutputPath)\App_Browsers"></MakeDir>
      <Copy SourceFiles="@(MySourceFiles)" 
            DestinationFiles="@(MySourceFiles->'$(OutputPath)\App_Browsers\%(RecursiveDir)%(Filename)%(Extension)')">
      </Copy>
  </Target>

Hope it helps others, stuck with the same problem.