我想知道如何在SharePoint解决方案中构建后编译ASPX文件,以查看运行时错误,例如缺少资源(使用资源翻译页面时)。

当我将aspnetcompiler任务添加到我的csproj中(仅显示项目文件的末尾):

...
<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <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" -->
  </Target>
  <PropertyGroup>
    <PostBuildEvent>
    </PostBuildEvent>
  </PropertyGroup>
</Project>
. 然后在构建项目时,我在aspx文件中获得以下错误:

无法加载文件或装配'$ sharepoint.project.assemblyfullname $'或其依赖项之一。系统找不到指定的文件。

显然,ASP编译器尝试在项目目录中构建没有令牌的项目目录中的aspx文件。但是,我无法完成任务,因此它将在替换令牌的字段上运行。我对MSBuild的了解是有限的,这可能是问题。

有帮助吗?

解决方案

令牌替换的唯一方法是创建WSP包,因为替换发生在那里。然后解决方案是为了创建WSP,将其解压缩到目标文件夹,创建一个名为“bin”的新目录,将dll移动到bin目录,然后在目标文件夹上运行aspnet编译器。整个过程可以在MSBUILD(CSPROJ)文件中完成。这是我的解决方案 - 在CSProj文件的末尾,在导入SharePoint目标之后:

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

    <!-- define file/folder properties -->
    <ExpandDest>$(TargetDir)_wsp</ExpandDest>
    <WspBinPath>$(ExpandDest)\bin</WspBinPath>
    <WspPath>$(TargetDir)MyProject.wsp</WspPath>    
  </PropertyGroup>

  <!-- 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 -->
    <AspNetCompiler 
      VirtualPath="/"
      PhysicalPath="$(ExpandDest)"
      Clean="true"
      ContinueOnError="false"
      ToolPath="C:\Windows\Microsoft.NET\Framework\v2.0.50727" />
  </Target>
</Project>
.

编辑:过程有点复杂。根据您自己的项目,您必须将一些文件移动到特定文件夹。基本上,按照编译器告诉你的讲述。

许可以下: CC-BY-SA归因
scroll top