我試圖在我們的Sharepoint解決方案中實現一個插件架構,此時管理員可以上傳將由我們的解決方案安裝和處理的dll文件。GacInstall在Sharepoint計時器作業a.k.a SPJobDefinition
實現需要GAC安裝上傳的DLL文件的,我已經使用
private void InstallToGac(byte[] libraryContent, string filename)
{
string path = tempFolder + filename;
File.WriteAllBytes(path, libraryContent);
try
{
new System.EnterpriseServices.Internal.Publish().GacInstall(path);
}
catch (Exception ex)
{
Logger.Error("Error while installing dll to GAC.", ex);
throw;
}
finally
{
File.Delete(path);
}
}
這只是安裝DLL到GAC,如果它的Sharepoint內部調用工作正常完成。但是,它不適用於多服務器環境,因爲這隻會將其安裝在管理員上傳文件的前端。因此,我通過繼承SPJobDefinition
將上面的代碼移到了計時器作業中。 GacInstall不再安裝dll到GAC了。在調試模式下,GacInstall
行工作正常,沒有任何異常,但沒有任何影響。
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
在計時器作業中返回Network Service
。我在單服務器Sharepoint 2010 Foundation上工作,但我需要在單服務器和多服務器環境上工作於2007/2010/2013。