GVKun编程网logo

如何在Powershell中修改GOPATH(powershell怎么修改路径)

10

在这篇文章中,我们将带领您了解如何在Powershell中修改GOPATH的全貌,包括powershell怎么修改路径的相关情况。同时,我们还将为您介绍有关.net–如何在PowerShell中引用U

在这篇文章中,我们将带领您了解如何在Powershell中修改GOPATH的全貌,包括powershell怎么修改路径的相关情况。同时,我们还将为您介绍有关.net – 如何在PowerShell中引用UWP类、bash – Powershell中的CDPATH功能?、powershell-v2.0 – 如何在Powershell中使用BITS上传/下载文件?、Powershell小技巧之使用Jint引擎在PowerShell中执行Javascript函数的知识,以帮助您更好地理解这个主题。

本文目录一览:

如何在Powershell中修改GOPATH(powershell怎么修改路径)

如何在Powershell中修改GOPATH(powershell怎么修改路径)

我正在尝试将我的项目目录添加到GOPATH,在Linux中,我可以这样做

export GOPATH=$HOME/mygo 在〜/ .bashrc中

Powershell中的等效性是什么

.net – 如何在PowerShell中引用UWP类

.net – 如何在PowerShell中引用UWP类

我想使用通用 Windows平台库中的数据类型,如何在PowerShell中引用包含的命名空间或程序集?

例如,我想用Windows.Data.Json.JsonObject class来解析一些json.

如果这是一个常规的.NET类,我会做类似的事情

Add-Type -AssemblyName Windows.Data.Json
$jsonObject = [Windows.Data.Json.JsonObject]::Parse('{data:["powershell","rocks"]}')

但这个策略让我失望:

Add-Type : Cannot add type. The assembly 'Windows.Data.Json' Could not be found.
At line:1 char:1
+ Add-Type -AssemblyName Windows.Data.Json
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Windows.Data.Json:String) [Add-Type],Exception
    + FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand

现在,假设Windows.Data.Json命名空间的程序集是Windows.Data.Json.dll,我可能完全错了,但API引用实际上似乎不包含对包含文件的任何引用,我相信一个DLL文件实际上不是我应该寻找的.

我假设UWP有自己的酷GAC类商店,我可以从中加载共享库,我只是不知道如何.

基本上我的问题是,我如何将一个UWP共享库加载到PowerShell中,我应该如何引用UWP类型的文字?

在Windows 10上运行PowerShell 5.1(内部版本1703)

发布此问题后不久,我偶然发现 the GitHub repo for BurntToast,一个允许从PowerShell提升UWP Toast Notifications的模块,它引用了WinRT Toastnotificationmanager类型,如下所示:
[Windows.UI.Notifications.Toastnotificationmanager,Windows.UI.Notifications,ContentType = WindowsRuntime]

所以,看起来我对UWP类的语法是:

[<class name>,<namespace>,ContentType = WindowsRuntime]

考虑到这一点,我尝试了我在问题中给出的例子,并且看到:

PS C:\> $jsonObjectClass = [Windows.Data.Json.JsonObject,Windows.Data.Json,ContentType=WindowsRuntime]
PS C:\> $jsonObject = $jsonObjectClass::Parse('{"data":["powershell","rocks"]}')
PS C:\> $jsonObject

Key  Value                 
---  -----                 
data ["powershell","rocks"]

在引用类型名称一次后,我似乎能够在类型文字中使用类名而不限定它:

[Windows.Data.Json.JsonObject]::Parse("{}") # works without throwing errors Now

尽管如此,仍然非常希望找到任何关于此的文档

bash – Powershell中的CDPATH功能?

bash – Powershell中的CDPATH功能?

有人在Power shell中实现了 bash’s ‘cdpath’的等效行为吗?

解决方法

之前不知道Cdpath.很高兴知道.我为Powershell掀起了以下内容:

function cd2 {
    param($path)
    if(-not $path){return;}

    if((test-path $path) -or (-not $env:Cdpath)){
        Set-Location $path
        return
    }
    $cdpath = $env:Cdpath.split(";") | % { $ExecutionContext.InvokeCommand.ExpandString($_) }
    $npath = ""
    foreach($p in $cdpath){
        $tpath = join-path $p $path
        if(test-path $tpath){$npath = $tpath; break;}
    }
    if($npath){
        #write-host -fore yellow "Using Cdpath"
        Set-Location $npath
        return
    }

    set-location $path

}

它不会是完美的,但是以预期的方式工作.我猜你可以扩展它.将其添加到您的个人资料.如果需要,还可以添加如下别名:

set-alias -Name cd -value cd2 -Option AllScope

powershell-v2.0 – 如何在Powershell中使用BITS上传/下载文件?

powershell-v2.0 – 如何在Powershell中使用BITS上传/下载文件?

我在谷歌发现了一些关于此的页面,但它们要么不完整,要么过时.某处有明确的指导吗?谢谢

解决方法

Power Shell中始终提供帮助:

PS> import-module bitstransfer
PS> gcm *bits* | ? {$_.Commandtype -eq "cmdlet"}

CommandType Name                  DeFinition
----------- ----                  ----------
Cmdlet      Add-BitsFile          Add-BitsFile [-BitsJob] <BitsJob[]> [-S...
Cmdlet      Complete-BitsTransfer Complete-BitsTransfer [-BitsJob] <BitsJ...
Cmdlet      Get-BitsTransfer      Get-BitsTransfer [[-Name] <String[]>] [...
Cmdlet      Remove-BitsTransfer   Remove-BitsTransfer [-BitsJob] <BitsJob...
Cmdlet      Resume-BitsTransfer   Resume-BitsTransfer [-BitsJob] <BitsJob...
Cmdlet      Set-BitsTransfer      Set-BitsTransfer [-BitsJob] <BitsJob[]>...
Cmdlet      Start-BitsTransfer    Start-BitsTransfer [-Source] <String[]>...
Cmdlet      Suspend-BitsTransfer  Suspend-BitsTransfer [-BitsJob] <BitsJo...

告诉你可用的命令.

然后,您可以在这些上调用Get-Help.根据我所见,帮助条目非常有用.并且不要忘记Get-Help … – 示例详细和注释用法示例.并且cmdlet已经被命名为不言自明.

Powershell小技巧之使用Jint引擎在PowerShell中执行Javascript函数

Powershell小技巧之使用Jint引擎在PowerShell中执行Javascript函数

这里演示如何利用PowerShell将一段Javascript函数字符串交给Jint引擎去执行。

执行Javascript函数

执行Javascript函数

.Net版的Javascript解释器

可以从Git上获取Jint的代码,也可以从nuget上下载Jint的程序集。

Jint是一个面向.Net的Javascript解释器。Jint不会把Javascript编译成.Net字节码,所以它非常适用于脚本小且运行起来速度快的工程,或者运行在不同平台上的脚本。

PowerShell调用

拿到Dll根据-Path参数直接使用Add-Type命令即可:

function Invoke-JSAdd ($a, $b) {             
    Add-Type –Path  "C:\jint\Jint.dll"           
             
    $JavaScript = "
        function add(a, b) { 
            return a + b; 
        }
    "           
    $add = (New-Object Jint.Engine).            
            Execute($JavaScript).            
            GetValue("add")            
             
    $add.Invoke($a, $b).ToString()            
}

 

您可能感兴趣的文章:
  • JavaScript判断页面加载完之后再执行预定函数的技巧
  • JavaScript中split与join函数的进阶使用技巧
  • 个人总结的一些JavaScript技巧、实用函数、简洁方法、编程细节
  • 检测一个函数是否是JavaScript原生函数的小技巧
  • JavaScript中的alert()函数使用技巧详解
  • Javascript中产生固定结果的函数优化技巧
  • js中字符替换函数String.replace()使用技巧
  • js函数使用技巧之 setTimeout(function(){},0)
  • js 格式化时间日期函数小结
  • javascript函数中的3个高级技巧

今天关于如何在Powershell中修改GOPATHpowershell怎么修改路径的讲解已经结束,谢谢您的阅读,如果想了解更多关于.net – 如何在PowerShell中引用UWP类、bash – Powershell中的CDPATH功能?、powershell-v2.0 – 如何在Powershell中使用BITS上传/下载文件?、Powershell小技巧之使用Jint引擎在PowerShell中执行Javascript函数的相关知识,请在本站搜索。

本文标签: