【问题标题】:Execution policy error by running "yo office" in office add-in generator Yeoman [duplicate]在 Office 插件生成器 Yeoman 中运行“yo office”导致执行策略错误 [重复]
【发布时间】:2021-12-04 00:45:07
【问题描述】:

我想使用 yeoman 为带有 angular 的办公室创建一个插件。安装需求工具后,如 nodeJs, angular, yeoman, generator-office in power shell,我尝试运行这段代码

yo office 

但是我收到了这个错误:

 yo : File C:\Users\ME\AppData\Roaming\npm\yo.ps1 cannot be loaded. 
The file C:\Users\ME\AppData\Roaming\npm\yo.ps1 is not digitally signed. 
You cannot run this script on the current system. 
For more information about running scripts and setting execution policy, 
see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ yo office
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess  

【问题讨论】:

  • 以下是基于default配置的一般信息;您的有效执行政策似乎是AllSigned;有关详细信息,请参阅链接的副本或this answer
  • 在 Windows 工作站上,PowerShell 脚本执行默认被禁用。使用 Set-ExecutionPolicy.-Scope 启用它接受 3 个范围之一;更具体的优先级更高:LocalMachine(需要管理员权限)、CurrentUserProcess(仅限当前进程)。 PowerShell CLI 也接受特定于进程的 -ExecutionPolicy <policy> 。执行策略也可以通过 GPO 设置,在这种情况下,它们不能通过Set-ExecutionPolicy 或 CLI 更改或覆盖。

标签: angular powershell yeoman office-addins project-web-addins


【解决方案1】:

在我在这里阅读了这个链接中的这个错误之后,我发现我应该改变“currentUser”的执行策略。

  1. 运行此代码以在 PowerShell 中查看系统的执行策略。
Get-ExecutionPolicy -List
  1. 如果您的 CurrentUser ExecutionPolicy 是“未定义”,则应使用此代码将其更改为“RemoteSigned”
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

我已经在 windows 10 pro x64、Yeoman 4.3.0、NodeJs 14.17.0、NPM 6.14.13 中测试过

【讨论】:

    猜你喜欢
    • 2021-10-18
    • 2021-07-17
    • 1970-01-01
    • 2019-11-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 2014-05-19
    • 1970-01-01
    相关资源
    最近更新 更多