相关疑难解决方法(0)

无法加载ps1,因为在此系统上禁用了运行脚本

我尝试powershell从c#运行脚本.

首先,我设置ExecutionPolicyUnrestricted和脚本从现在正在运行PowerShell ISE.

现在这是我的代码:

class Program
{
    private static PowerShell ps;
    static void Main(string[] args)
    {
        ps = PowerShell.Create();
        string ps1File = Path.Combine(Environment.CurrentDirectory, "script.ps1");
        ExecuteScript(ps1File);
        Console.ReadLine();
    }

    static void ExecuteScript(string script)
    {
        try
        {
            ps.AddScript(script);
            Collection<PSObject> results = ps.Invoke();
            Console.WriteLine("Output:");
            foreach (var psObject in results)
            {
                Console.WriteLine(psObject);
            }
            Console.WriteLine("Non-terminating errors:");
            foreach (ErrorRecord err in ps.Streams.Error)
            {
                Console.WriteLine(err.ToString());
            }
        }
        catch (RuntimeException ex)
        {
            Console.WriteLine("Terminating error:");
            Console.WriteLine(ex.Message);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出是:

无法加载ps1,因为在此系统上禁用了运行脚本.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=135170上的 …

c# powershell

14
推荐指数
16
解决办法
2万
查看次数

使用 npm install tr​​uffle -g 在 Windows 10 上安装 Truffle 时出现错误

当我尝试安装 truffle 时,出现以下错误:-

我之前已经安装了 Node.js,并且还安装了 pip。

PS C:\Users\pk199\Documents> npm install -g truffle

npm ERR! code 1
npm ERR! path C:\Users\pk199\AppData\Roaming\npm\node_modules\truffle\node_modules\ganache\node_modules\leveldown
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.3.0
npm ERR! gyp info using node@16.13.1 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.1 found at "C:\Users\pk199\AppData\Local\Programs\Python\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm …
Run Code Online (Sandbox Code Playgroud)

visual-studio npm-install truffle

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

npm-install ×1

powershell ×1

truffle ×1

visual-studio ×1