You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否将Angular自定义原理图发布至Azure DevOps npm或私有仓库用作模板?

Publishing Custom Angular Schematics to Azure DevOps Artifacts for Project Templates

Absolutely! You totally can publish your custom Angular schematic collection to Azure DevOps Artifacts (or any private npm registry) and use it as a reusable project template with the Angular CLI's --collection flag. Let me walk you through how to set this up step by step:

1. Prepare Your Schematic Collection

First, make sure you've built out your custom schematic project. If you haven't started yet, create a new schematics workspace with:

ng new my-custom-schematics --create-application=false

Then add your schematic logic—define templates, modify the collection.json config, and test it locally to ensure it generates the exact project structure you want as a template.

2. Configure Your Package for Publishing

In your schematics project's package.json, double-check these key details:

  • A clear name (ideally scoped to your organization, like @your-org/custom-templates)
  • Correct version number (follow semantic versioning for updates)
  • A schematics field pointing to your collection config file:
    "schematics": "./src/collection.json"
    

Verify that collection.json correctly references your schematic's entry points and template paths—this tells Angular CLI where to find your generation logic.

3. Authenticate with Azure DevOps Artifacts

Before publishing, you need to connect your local npm to your Azure DevOps feed:

  1. Get a Personal Access Token (PAT) from Azure DevOps: Go to your profile → Security → Personal access tokens, create one with at least Packaging (Read & Write) permissions.
  2. Configure npm to use your Azure feed:
    npm config set registry https://pkgs.dev.azure.com/[Your-Org-Name]/[Your-Project-Name]/_packaging/[Your-Feed-Name]/npm/registry/
    
  3. Log in to the registry:
    npm login --registry=https://pkgs.dev.azure.com/[Your-Org-Name]/[Your-Project-Name]/_packaging/[Your-Feed-Name]/npm/registry/
    
    When prompted, enter any username (it’s ignored) and use your PAT as the password.

4. Publish the Schematic Collection

Head to your schematics project root and run:

npm publish

Once successful, you’ll see your package listed in your Azure DevOps Artifacts feed.

5. Use the Template with Angular CLI

Now you can generate new projects using your private schematic collection:

  • If your npm is already configured to use the Azure feed as default, just run:
    ng new my-new-project --collection=@your-org/custom-templates
    
  • If you use multiple registries, either install the schematic package globally first:
    npm install -g @your-org/custom-templates --registry=https://pkgs.dev.azure.com/[Your-Org-Name]/[Your-Project-Name]/_packaging/[Your-Feed-Name]/npm/registry/
    
    Or configure your organization’s npm scope to point to the Azure feed permanently:
    npm config set @your-org:registry https://pkgs.dev.azure.com/[Your-Org-Name]/[Your-Project-Name]/_packaging/[Your-Feed-Name]/npm/registry/
    
    This way, you won’t need to specify the registry every time you install or use packages under @your-org.

Quick Tips

  • Test your schematic locally first with npm link to avoid publishing broken versions.
  • Update your PAT if it expires to keep publishing access.
  • Use semantic versioning (e.g., 1.0.0, 1.0.1) to manage updates to your template.

内容的提问来源于stack exchange,提问作者Henzard Kruger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 13:27:31