I would like to know how to compile aspx files after build in a SharePoint solution to see the run-time errors, e.g. missing resource (when translating the page using resources).

When I add the AspNetCompiler task into my csproj like this (only showing the end of the project file):

    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  <Import Project="$(VSToolsPath)\SharePointTools\Microsoft.VisualStudio.SharePoint.targets" Condition="'$(VSToolsPath)' != ''" />
  <Target Name="AfterBuild">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" />
    <!-- ToolPath="C:\Windows\Microsoft.NET\Framework64\v2.0.50727" -->

Then when building the project I get the following error in the aspx file:

Could not load file or assembly '$SharePoint.Project.AssemblyFullName$' or one of its dependencies. The system cannot find the file specified.

Obviously the asp compiler tries to build the aspx files in the project directory which do not have the tokens replaced. However, I was unable to finalise the task so it would operate on fields with the tokens replaced. My knowledge of MSBuild is limited which might be the problem.


The only way to do the token replacement is to create the wsp package because the replacement occurs there. The solution is then to create the wsp, unpack it to a target folder, create a new directory there called "bin", move the dlls to the bin directory and then run aspnet compiler on the target folder. The whole process can be done in MSBUild (csproj) file. This is my solution - at the end of the csproj file, after the sharepoint targets are imported:

  <Import Project="$(VSToolsPath)\SharePointTools\Microsoft.VisualStudio.SharePoint.targets" Condition="'$(VSToolsPath)' != ''" />
    <!-- schedule creating the package in the build, the task is defined in sharepoint targets -->

    <!-- define file/folder properties -->

  <!-- override "after build" target, it must depend on the package creation, 
       which ensures that the target runs after we have the wsp package ready -->
  <Target Name="AfterBuild" DependsOnTargets="CreatePackage">
    <!-- create the folder where we unpack our wsp -->
    <MakeDir Directories="$(ExpandDest)" />    
    <!-- use expand to unpack the wsp -->
    <Message Text="$(ExpandWsp)" Importance="high" />
    <Exec Command="expand &quot;$(WspPath)&quot; -F:* &quot;$(ExpandDest)&quot;" />

    <!-- create the "bin" folder -->
    <MakeDir Directories="$(WspBinPath)" />
    <!-- move all dlls and xmls from the root to the bin folder -->
    <Exec Command="move /Y &quot;$(ExpandDest)\*.dll&quot; &quot;$(WspBinPath)&quot;" />
    <Exec Command="move /Y &quot;$(ExpandDest)\*.xml&quot; &quot;$(WspBinPath)&quot;" />

    <!-- run the aspnet compiler on the wsp folder,
         the tool path param ensures that .net 2 compiler will be used,
         we need that because we compile sharepoint 2010 which is .net 3.5
         and the latest aspnet compiler for .net 3.5 is in .net 2 -->
      ToolPath="C:\Windows\Microsoft.NET\Framework\v2.0.50727" />

EDIT: The process is a bit more complicated. According to your own project, you have to move some files to specific folders. Basically, follow what you are told by the compiler.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.