Pergunta

Gostaria de saber como compilar arquivos aspx após construir uma solução SharePoint para ver os erros em tempo de execução, por exemplo.recurso ausente (ao traduzir a página usando recursos).

Quando adiciono a tarefa AspNetCompiler em meu csproj assim (mostrando apenas o final do arquivo do projeto):

...
<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>

Então, ao construir o projeto, recebo o seguinte erro no arquivo aspx:

Não foi possível carregar o arquivo ou assembly '$SharePoint.Project.AssemblyFullName$' ou uma de suas dependências.O sistema não pode encontrar o arquivo especificado.

Obviamente, o compilador asp tenta construir os arquivos aspx no diretório do projeto que não possuem os tokens substituídos.Porém, não consegui finalizar a tarefa para que ela operasse nos campos com os tokens substituídos.Meu conhecimento do MSBuild é limitado, o que pode ser o problema.

Foi útil?

Solução

A única maneira de fazer a substituição do token é criar o pacote wsp porque a substituição ocorre lá.A solução é então criar o wsp, descompactá-lo em uma pasta de destino, criar um novo diretório chamado "bin", mover as dlls para o diretório bin e executar o compilador aspnet na pasta de destino.Todo o processo pode ser feito no arquivo MSBUild (csproj).Esta é a minha solução - no final do arquivo csproj, após a importação dos destinos do 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>

EDITAR: O processo é um pouco mais complicado.De acordo com o seu projeto, você deve mover alguns arquivos para pastas específicas.Basicamente, siga o que o compilador lhe disser.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top