zoukankan      html  css  js  c++  java
  • Running powershell scripts during nuget package installation and removal

    示范:

     1 param($installPath, $toolsPath, $package)
     2 
     3 function Uninstall-ProjectPackages($project) {
     4     #remove no use dlls
     5     $project.Object.References | Where-Object {  $_.Name -eq 'A.ServiceInterface' } | ForEach-Object { $_.Remove() }
     6     # save project
     7     $project.Save()
     8 }
     9 
    10 
    11 $projects = Get-Project -All
    12 $projects| ForEach-Object { Uninstall-ProjectPackages $_ }

    Running powershell scripts during nuget package installation and removal

    来源:https://everydaylifein.net/netframework/running-powershell-scripts-during-nuget-package-installation-and-removal.html#:~:text=Your%20NuGet%20package%20can%20contain%20PowerShell%20scripts%20which%2C,supported%20in%20Visual%20Studio%202017%20%28%20read%20more%29

    Your NuGet package can contain PowerShell scripts which, based on a convention, will be called during the package installation/removal process.

    • Init.ps1 runs the first time a package is installed in a solution
    • Install.ps1 runs when a package is installed in a project <- no longer supported in Visual Studio 2017 (read more)
    • Uninstall.ps1 runs every time a package is uninstalled <- no longer supported in Visual Studio 2017 (read more)
    • you can read more about it here

    Your scripts should begin with the following line

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

    Where

    • $installPath path to where the project is installed
    • $toolsPath path to the extracted tools directory
    • $package information about the currently installing package
    • $project reference to the EnvDTE project the package is being installed into

    In order to be executed, the scripts need to be included in the tools directory of the nuget package. You can achieve this by editing your *.nuspec file and adding a file reference.

    <?xml version="1.0"?>
    <package >
      <metadata>...</metadata>
      <files>
    	<file src="scriptsNugetScriptsInstall.ps1" target="toolsInstall.ps1" />
      </files>
    </package>
    

    You will quickly find debugging to be fairly painful if you need to operate with the $project reference. In this case, you are highly encouraged to test all your $project actions in the Visual Studio Package Manager Console by writing

    $project = Get-Project
    

    Now you can interactively test your operations in the console, and you don’t have to constantly pack and install/uninstall your package to check if the scripts work as intended.

  • 相关阅读:
    排序希尔排序
    Sentinel 限流
    排序基数排序
    【ProToolkit范例之三】遍历模型下的所有Feature
    【ProToolkit范例之四】创建udf
    【ProToolkit范例之五】输出Asm的架构
    鼠标滚轮改变文本框值的jQuery插件cutePsWheel发布
    自己做手做“分享到”小工具
    深入理解jQuery AJAX调用页面内Web服务
    没错,你没有看错,博客园Android客户端开源了!
  • 原文地址:https://www.cnblogs.com/micro-chen/p/15137620.html
Copyright © 2011-2022 走看看