2012-03-18 65 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