SharePointプロジェクトのASPNetCompilerタスク
質問
SharePointソリューションに構築した後にASPXファイルをコンパイルする方法を知りたいのですが、ランタイムエラー(例:)不足しているリソース(ページをリソースを使用して翻訳するとき)
ASPNetCompilerタスクをこのようにMy 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>
.
Projectを構築するとき、ASPXファイルに次のエラーが発生します。
ファイルまたはアセンブリの「$ SharePoint.Project.AssemblyFullName $」またはその依存関係の1つをロードできませんでした。システムは指定されたファイルを見つけることができません。
明らかに、ASPコンパイラは、トークンが置き換えられていないプロジェクトディレクトリにASPXファイルを構築しようとします。ただし、トークンが置き換えられたフィールドで動作するようにタスクを確定できませんでした。MSBUILDについての私の知る限りは問題があるかもしれません。
解決
トークンの交換を行う唯一の方法は、置換が発生したためにWSPパッケージを作成することです。その場合、解決策はWSPを作成し、ターゲットフォルダに解凍され、そこで「bin」と呼ばれる新しいディレクトリを作成し、DLLをbinディレクトリに移動してから、ターゲットフォルダのASPNetコンパイラを実行します。プロセス全体をMSBUILD(CSPROJ)ファイルで実行できます。これは私の解決策です - SharePointターゲットがインポートされた後のCSPROJファイルの最後にあります。
<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 "$(WspPath)" -F:* "$(ExpandDest)"" />
<!-- create the "bin" folder -->
<MakeDir Directories="$(WspBinPath)" />
<!-- move all dlls and xmls from the root to the bin folder -->
<Exec Command="move /Y "$(ExpandDest)\*.dll" "$(WspBinPath)"" />
<Exec Command="move /Y "$(ExpandDest)\*.xml" "$(WspBinPath)"" />
<!-- 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>
.
編集:プロセスはもう少し複雑です。あなた自身のプロジェクトによると、いくつかのファイルを特定のフォルダに移動する必要があります。基本的に、あなたがコンパイラによって言われたものに従ってください。