2012-03-18 36 views
0

我想爲MEF插件編寫nuspec。 我可以將xxx.dll複製到內容目錄中,如下所示。我怎樣才能爲MEF插件文件編寫Nuspec

<files> 
    <file src="Alhambra\bin\Release\Plugins\Alhambra.Plugin.SqlServer.dll" target="content\Plugins\Alhambra.Plugin.SqlServer.dll" /> 
    <file src="Alhambra\bin\Release\Alhambra.dll" target="lib\Alhambra.dll" /> 
</files> 

但我不能在用戶項目中設置文件屬性來複制輸出目錄。

感謝您的任何建議或代碼片段。

回答

0

我的方法是將插件作爲單獨的文件添加到項目中。爲此,您需要安裝腳本(請參閱NuGet docs for this)。

我對這個解決方案是下面的腳本:

參數($ INSTALLPATH,$ toolsPath,$包,$項目)

Function add_file($file) 
{ 
    $do_add = 1 
    foreach($item in $project.DTE.ActiveSolutionProjects[0].ProjectItems) 
    { 
     if ($item -eq $file) 
     { $do_add = 0 } 
    } 
    if ($do_add -eq 1) 
    { 
     $added = $project.DTE.ItemOperations.AddExistingItem($file) 
     $added.Properties.Item("CopyToOutputDirectory").Value = 2 
     $added.Properties.Item("BuildAction").Value = 0   
    } 
} 
add_file(<file1>) 
add_file(<file2>) 

當然,當用戶卸載包,你需要清理:

param($installPath, $toolsPath, $package, $project) 

Function remove_file($file) 
{ 
    foreach($item in $project.DTE.ActiveSolutionProjects[0].ProjectItems) 
    { 
     if ($item.Name -eq $file) 
     { 
      $item.Delete() 
     } 
    } 
} 
remove_file(<file1>) 
remove_file(<file2>) 
+0

請注意,從nuget控制檯使用''install-package''命令時不起作用。它會嘗試將這些文件添加爲解決方案項目。 – miracle2k 2012-12-31 12:50:59