如何在Azure DevOps构建流水线中为Web App添加Common项目引用?
Hey there! Let's fix that build pipeline error you're hitting with your Web App that relies on the Common project. The core issue is your pipeline isn't accounting for the Common dependency—either it's not pulling the project in, or it's not building it before the Web App. Here's how to resolve this for the most common pipeline tools:
GitHub Actions
- Check out the right code:
- If both projects live in the same repo: The default
actions/checkout@v4step will grab everything, but double-check you haven't added path restrictions that exclude the Common project. - If they're in separate repos: Add an extra checkout step to pull the Common repo into your pipeline workspace:
- name: Checkout Common project uses: actions/checkout@v4 with: repository: your-username/CommonRepo ref: main path: ./Common
- If both projects live in the same repo: The default
- Build Common first (or use a solution file):
- For .NET apps: Either build the Common project explicitly before the Web App, or build the entire solution that includes both:
# Option 1: Build Common separately - name: Build Common project run: dotnet build ./Common/Common.csproj --configuration Release - name: Build Web App run: dotnet build ./WebApp/WebApp.csproj --configuration Release # Option 2: Build the solution (simpler if you have one) - name: Build entire solution run: dotnet build YourSolution.sln --configuration Release - For JS/TS apps: Link the Common project as a local dependency before building:
- name: Install and link Common package run: npm install ./Common working-directory: ./WebApp - name: Build Web App run: npm run build working-directory: ./WebApp
- For .NET apps: Either build the Common project explicitly before the Web App, or build the entire solution that includes both:
Azure DevOps Pipelines
- Fetch both projects:
- Same repo: The default
checkout: selftask works fine—no extra steps needed. - Separate repos: Add a second checkout task to pull the Common project:
- checkout: git://YourOrganization/CommonRepo@main path: s/Common
- Same repo: The default
- Build the dependency first:
- Use the
DotNetCoreCLItask for .NET projects to build Common before the Web App:- task: DotNetCoreCLI@2 displayName: Build Common project inputs: command: 'build' projects: '**/Common.csproj' arguments: '--configuration Release' - task: DotNetCoreCLI@2 displayName: Build Web App inputs: command: 'build' projects: '**/WebApp.csproj' arguments: '--configuration Release' - Alternatively, build the solution file if you have one—it will handle the dependency order automatically.
- Use the
Jenkins
- Check out your repos:
- Same repo: Just clone the repo as usual:
git url: 'https://your-repo-url.git', branch: 'main' - Separate repos: Clone both, placing Common in a subdirectory:
git url: 'https://web-app-repo.git', branch: 'main' git url: 'https://common-repo.git', branch: 'main', destination: 'Common'
- Same repo: Just clone the repo as usual:
- Build Common before the Web App:
- For Java/Maven: Install the Common artifact to the local Maven repo so the Web App can access it:
sh 'mvn clean install -f Common/pom.xml' sh 'mvn clean package -f WebApp/pom.xml' - For .NET: Build Common first, then the Web App:
sh 'dotnet build Common/Common.csproj --configuration Release' sh 'dotnet build WebApp/WebApp.csproj --configuration Release'
- For Java/Maven: Install the Common artifact to the local Maven repo so the Web App can access it:
Quick General Checks
- Verify the reference path in your Web App project file matches where the Common project lives in the pipeline workspace. For example, if Common is in
./Common, your .NET project should have<ProjectReference Include="..\Common\Common.csproj" />. - If you're working in a larger team, consider publishing the Common project to a package registry (NuGet, npm, Maven Central) instead. Then your Web App can pull it as a regular dependency, which avoids checking in the Common code directly into the pipeline.
内容的提问来源于stack exchange,提问作者M0rty
相关产品推荐
相关产品推荐

