Publish via Visual Studio partially ignoring selected Enviroment
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
Publishing from Visual Studio to Azure seems to be partially ignoring the selected environment.
All logs in publish window and output are showing the correct details for the selected environment, however fails at deploying the first service. The error message implies that Aspire is using the wrong Container Registry, in a different environment, and I have confirmed on Azure that it has indeed published to to wrong registry and deployment fails because the correct ACA doesn't have access to that registry
### Expected Behavior
Aspire/VS respects the selected Environment when publishing
### Steps To Reproduce
_No response_
### Exceptions (if any)
ContainerAppOperationError: Failed to provision revision for container app 'webmain'. Error details: The following field(s) are either invalid or missing. Field 'template.containers.webmain.image' is invalid with details: 'Invalid value: "plstagingxxxx.azurecr.io/xxxx/webmain-xxx-dev:azd-deploy-1769721542": GET https:?scope=repository%3Axxxx%2Fwebmain-xxx-dev%3Apull&service=plstagingacreyzvxjgvza3j2.azurecr.io: UNAUTHORIZED: authentication required, visit https://aka.ms/acr/authorization for more information. CorrelationId: e18ea6bc-12f8-4196-8066-1e8c4e2da65d';..
### .NET Version info
10.0.102
### Anything else?
Firstly, I have been using this workflow for many versions of Aspire with no issue, most recently 9.1 + .Net 8 + VS 2022.
I recently upgraded to Aspire 13, which required upgrading to .Net 10 which required upgrading to Visual Studio 2026.
I did test builds at each step, but I didn't try a publish until all steps had been complete so not sure which change actually caused this.
I have found a workaround, which is that if you change "defaultEnvironment" in Apphost/.azure/config.json to match the enviroment selected in Visual Studio, it publishes correctly.
Screenshot from VS and logs when publishing to plprod enviroment, but defaultEnviroment is set to plstaging:
[plprod deploy.txt](https://github.com/user-attachments/files/24948650/plprod.deploy.txt)
Contributor guide
Assessment
This issue has not been assessed yet.