Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to reference SDK without the version #2703

Closed
martincostello opened this issue Apr 13, 2024 · 6 comments
Closed

Ability to reference SDK without the version #2703

martincostello opened this issue Apr 13, 2024 · 6 comments

Comments

@martincostello
Copy link

Summary

I don't know if this a general MSBuild restriction, or specific to the new SDK, so this might not be the right place to feedback on this.

Add the ability to reference the SDK without the version number, for example:

- <Project Sdk="MSTest.Sdk/3.3.1">
+ <Project Sdk="MSTest.Sdk">

Background and Motivation

Requiring the Sdk to include the version is not friendly to package updating tools or NuGet Central Package Version Management where the aim is to define the package version(s) in exactly one place and to then allow them to be easily maintained in an automated version with tools such as dependabot or dotnet-outdated.

I experimented with using an MSBuild property for the version, but MSBuild does not appear to use the value late enough in project loading to be able to use that approach.

Proposed Feature

Somehow allow the SDK to be loaded/referenced without an explicit version number by loading it from the package reference (e.g. from <PackageVersion Include="MSTest.TestFramework" Version="3.3.1" />).

Alternative Designs

None.

@MarcoRossignoli
Copy link
Contributor

MarcoRossignoli commented Apr 15, 2024

Somehow allow the SDK to be loaded/referenced without an explicit version number by loading it from the package reference (e.g. from ).

Hi @martincostello, the MSBuild sdk versioning doesn't allow the usage of the NuGet Central Package Version Management

As you can see here https://github.com/microsoft/testfx/tree/main/src/Package/MSTest.Sdk/Sdk an MSBuild SDK is a bunch of props/targets that we compose (for instance this is the main file https://github.com/microsoft/testfx/blob/main/src/Package/MSTest.Sdk/Sdk/Runner/ClassicEngine.targets).

So it's not easy have 1 version for everything because the imports will import more packages with different versions. So our 3.1.1 sdk actually is the "version" of MSTest from feature perspective but it's composed by more packages from different part of the platform and with different versions. For instance the new testing platform(https://github.com/microsoft/testfx/blob/main/docs/testingplatform/Index.md) that empower the runner is at the moment at version 1.1.0.

The only way at the moment to centralize the version at solution level is to use the global.json as explained here https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2022#how-project-sdks-are-resolved

When the version is missing the resolver goes to the default installed MSBuild sdks (i.e. C:\Program Files\dotnet\sdk\8.0.104\Sdks) or to NuGet(available feeds) using the version specified inside the global.json.

@martincostello
Copy link
Author

Thanks for the information - I'll have a look to see if adding the SDK in global.json works.

martincostello added a commit to martincostello/alexa-london-travel that referenced this issue Apr 15, 2024
Use MSBuild SDK in `global.json` for the version of `MSTest.Sdk` so that dependabot can update it at the same time as `MSTest.TestFramework`.
See microsoft/testfx#2703 (comment).
@martincostello
Copy link
Author

That did the trick - maybe worth calling out in some documentation somewhere? I originally just copy-pasted from the samples in the blog post.

martincostello added a commit to martincostello/alexa-london-travel that referenced this issue Apr 15, 2024
Use MSBuild SDK in `global.json` for the version of `MSTest.Sdk` so that dependabot can update it at the same time as `MSTest.TestFramework`.
See microsoft/testfx#2703 (comment).
@MarcoRossignoli
Copy link
Contributor

That did the trick - maybe worth calling out in some documentation somewhere? I originally just copy-pasted from the samples in the blog post.

Good idea, it's in the note box under the code sample https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-sdk but looks like is not super clear, thanks for the suggestion.

@Evangelink
Copy link
Member

TODOs:

  • Update doc to make it clearer that global.json can be used and provide a full example
  • Make it clear this is the recommended pattern
  • Update SDK sample to add the global.json case

@Evangelink
Copy link
Member

@martincostello I will move on this ticket as completed as the docs and samples have been added/edited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants