Reference the Models package
-
Open the Tailspin.SpaceGame.Web.csproj file, add the following
PackageReference
, and save the file.<ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Tailspin.SpaceGame.Web.Models" Version="1.0.0" /> </ItemGroup>
-
Modify the version number to include the pre-release prefix that was generated during the build process. Here's an example.
<PackageReference Include="Tailspin.SpaceGame.Web.Models" Version="1.0.0-CI-20200610-165738" />
This references the Tailspin.SpaceGame.Web.Models package that you created in Azure Artifacts. Notice the version number, 1.0.0, plus the pre-release suffix. This matches the initial version that you published to Azure Artifacts in the previous part.
When you save the file, Visual Studio Code might ask you to restore dependencies. We're not going to run this locally, so there is no need to restore the dependencies.
Add the pipeline configuration
The models-package
branch doesn't contain an initial azure-pipelines.yml file. Here's your chance to create it.
-
From Visual Studio Code, select File > New File. Then select File > Save to save the blank file as azure-pipelines.yml in your project's root directory, such as ~/mslearn-tailspin-spacegame-web.
On Windows, ensure that you select YAML from the Save as type field.
-
Copy the following YAML code into azure-pipelines.yml:
trigger: - '*' pool: vmImage: 'ubuntu-18.04' demands: - npm variables: buildConfiguration: 'Release' wwwrootDir: 'Tailspin.SpaceGame.Web/wwwroot' dotnetSdkVersion: '3.1.300' steps: - task: UseDotNet@2 displayName: 'Use .NET Core SDK $(dotnetSdkVersion)' inputs: version: '$(dotnetSdkVersion)' - task: NuGetToolInstaller@0 inputs: versionSpec: '5.6.0' - task: Npm@1 displayName: 'Run npm install' inputs: verbose: false - script: './node_modules/.bin/node-sass $(wwwrootDir) --output $(wwwrootDir)' displayName: 'Compile Sass assets' - task: gulp@1 displayName: 'Run gulp tasks' - script: 'echo "$(Build.DefinitionName), $(Build.BuildId), $(Build.BuildNumber)" > buildinfo.txt' displayName: 'Write build info' workingDirectory: $(wwwrootDir) - task: NuGetCommand@2 displayName: 'Restore project dependencies' inputs: command: 'restore' restoreSolution: '**/*.sln' feedsToUse: 'select' vstsFeed: 'Space Game - web - Dependencies/Tailspin.SpaceGame.Web.Models' - task: DotNetCoreCLI@2 displayName: 'Build the project - $(buildConfiguration)' inputs: command: 'build' arguments: '--no-restore --configuration $(buildConfiguration)' projects: '**/*.csproj' - task: DotNetCoreCLI@2 displayName: 'Publish the project - $(buildConfiguration)' inputs: command: 'publish' projects: '**/*.csproj' publishWebProjects: false arguments: '--no-build --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)' zipAfterPublish: true - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: drop' condition: succeeded()
The highlighted code shows where the pipeline restores dependencies, and looks in your Azure Artifacts feed for the dependencies that might be there.
-
Stage, commit, and push your changes to GitHub.
git add . git commit -m "Add reference to Models package" git push origin models-package
-
Go to Microsoft Azure Pipelines and watch the build run. The build picks up your Models package from Azure Artifacts, and builds the project successfully.
原文:Reference the package from the application
https://docs.microsoft.com/zh-cn/learn/modules/manage-build-dependencies/6-consume-package