Installed version of .NET not respected.
Description:
When using the task the selected version of .NET is not respected when building.
Task version: 3 & 4
Platform:
- [ ] Ubuntu
- [ ] macOS
- [x] Windows
Runner type:
- [x] Hosted
- [ ] Self-hosted
Repro steps:
- name: Setup .NET 8.0.300
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.300
- name: Run Uno Check
shell: pwsh
run: |
dotnet tool install --global Uno.Check --version 1.25.1
uno-check -v --ci --non-interactive --fix --verbose --skip xcode --skip gtk3 --skip vswin --skip androidemulator --skip androidsdk --skip vsmac --skip dotnetnewunotemplates
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Build Packages
shell: pwsh
run: |
msbuild ./MySolution.sln /r /p:Configuration=Release ${{ inputs.build-args }}
Expected behavior: 8.0.300 should be used
Actual behavior: 8.0.303 is used even though 8.0.300 is installed and my workloads are installed to 8.0.300. This fails my build as the wrong version of .NET is used and the workloads are installed in a different version of .NET.
Hello @dansiegel 👋, Thank you for creating this issue. We will investigate it and get back to you as soon as we have some feedback.
@priya-kinthali Note that you can look at some actual build logs here: https://github.com/PrismLibrary/Prism/actions/runs/9984037920
Hello @dansiegel 👋,
It seems that the behavior you're encountering is due to the .NET CLI's default policy of using the latest installed SDK. Unless a specific version is specified in the global.json file, the latest .NET version installed on the runner will be used by default. For details on the currently preinstalled .NET SDK versions, please refer to the documentation.
To ensure that your project uses the specific SDK version 8.0.300, please create or update a global.json file in your repository with the following content:
{
"sdk": {
"version": "8.0.300"
}
}
I hope this helps! Please let us know if this resolves your issue or if you need further assistance.
Hello @dansiegel 👋,
Just a gentle reminder to check if the proposed solution of updating the global.json file with SDK version 8.0.300 resolved the issue.
Thank you!
This is generally pretty problematic for reproducible builds. Since we cannot control which version of .NET may be installed on a hosted agent. Blame the .NET team for their implementation of Workloads which continues to be a disaster!
It would seem to me that this task would perhaps need at the very least an optional behavior that can override the environment default to specify a specific version as the default version of .NET to use since a project may have a global.json that is specifying project SDK's.
Also keep in mind that it's generally not great to check in a specific version to a global.json for a public project as this often creates issues for the community to get started contributing.
Hello @dansiegel 👋,
Upon further investigation, I noticed that the issue seems to be related to how the version is specified in your workflow. Please note when you specify 8.0.300 without quotes, YAML interprets it as a floating-point number rather than a string. YAML then converts it to 8.0.3, which the setup-dotnet action interprets as 8.0.3xx, defaulting to the latest patch version, which is 8.0.303. Specifying the version in quotes ensures YAML treats it as a string, preserving the exact version number because the task input follow semver notation.
Please update your workflow to the following with your desired version:
- name: Setup .NET 8.0.300
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.300'
This should resolve the issue by explicitly specifying the SDK version you want to use. Can you please confirm this solution is working for you?
Hello @dansiegel 👋, Just a gentle reminder to check if the issue is resolved after updated the version as suggested in the previous comment. Thank you!
Hello @dansiegel 👋, Just giving you a gentle ping to see if there are any updates on your end regarding this issue? Thank you!
Hello @dansiegel, I hope the version update with quotes resolved the issue. Due to inactivity, I am closing this issue for now. In case of any concerns, please feel free to reopen this issue or create a new one. Thankyou!
Setting the version in the global.json fixed this issue for me.