Enforcing a Specific .NET SDK Version with the UseDotNet Task
You need to enforce that all builds in Azure Pipelines use a specific version of the .NET SDK. What is the best approach?
Quick Answer
The UseDotNet task downloads and installs a specific .NET SDK version onto the agent before the build runs, guaranteeing every pipeline uses exactly that version regardless of what's already on the machine. A pipeline variable or a global.json file alone doesn't install anything — without UseDotNet actually pulling the specified SDK, the build still falls back to whatever's pre-installed.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Add a UseDotNet task to the pipeline that specifies the required SDK version.
The UseDotNet task in Azure Pipelines can be configured to download and install a specific version of the .NET SDK, ensuring that all builds use exactly that version, regardless of what is pre-installed on the agent. Option B is incorrect because setting a pipeline variable DotNetVersion and using it in the DotNetCoreCLI task does not enforce the SDK version; the DotNetCoreCLI task uses the SDK already available on the agent, unless explicitly redirected, and the variable alone does not install or enforce a specific SDK. Option C is incorrect because installing the SDK manually via a script is not a reliable or repeatable approach; it depends on the agent's state and does not automatically enforce the version across different agents or pipeline runs. Option D is incorrect because including a global.json file in the repository does not guarantee that the required SDK version is installed on the agent; the build agent may not respect global.json if the specified SDK is not present, and there is no enforcement mechanism without additional steps.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Add a UseDotNet task to the pipeline that specifies the required SDK version.
Why this is correct
Correct: The UseDotNet task can download and install a specified .NET SDK version, enforcing it for the build.
- ✗
Set a pipeline variable DotNetVersion and use it in the DotNetCoreCLI task.
Why it's wrong here
Incorrect: A pipeline variable DotNetVersion, when used in DotNetCoreCLI task, does not enforce the SDK version; the task uses the agent's installed SDK unless overridden by additional configuration.
- ✗
Install the SDK manually on the build agent using a script.
Why it's wrong here
Incorrect: Installing the SDK manually via a script is not automated and repeatable; it may work on one agent but fails on others and is not enforced by the pipeline.
- ✗
Include a global.json file in the repository and rely on the build agent to respect it.
Why it's wrong here
Incorrect: A global.json file specifies the SDK version but does not install it; the build agent will only use it if that SDK is already available, otherwise the build may fail or use a different version.
Go deeper
Related to this question
Learn chapter
Introduction to DevOps and Azure DevOps
Key term
JSON
JSON is a lightweight, text-based format for storing and exchanging data that is easy for humans to read and write and easy for machines to parse and generate.
Key term
Agent
An agent is a software component that runs on a local machine to perform automated tasks, collect data, or execute commands as part of a larger system like CI/CD or monitoring.
About these practice questions
One of 823 original AZ-400 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on AZ-400
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. You have a YAML pipeline that builds a .NET application. You need to ensure that the pipeline uses the .NET SDK version 6.0.x. Which task should you add to the pipeline?
easy- ✓ A.UseDotNet@2
- B.NuGetToolInstaller@1
- C.DotNetCoreCLI@2
- D.PowerShell@2
Why A: The UseDotNet@2 task is the correct choice because it explicitly installs a specific .NET SDK version (6.0.x) on the build agent, ensuring the pipeline uses the required SDK for building the .NET application. This task downloads and caches the SDK, making it available for subsequent tasks like DotNetCoreCLI@2.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-400 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-400 exam.