Closed Tiberriver256 closed 3 months ago
vswhere is already added via nuget package in the TestProject folder: https://github.com/reqnroll/Reqnroll/blob/main/Reqnroll.TestProjectGenerator/Reqnroll.TestProjectGenerator/Reqnroll.TestProjectGenerator.csproj#L24
yeah, the issue is vswhere is specifically created to locate Visual Studio or other Microsoft-related build tooling. I think this leaves out .net tooling installed through Jetbrains products, the C# Dev Kit for Visual Studio Code or even a direct install of .NET SDK
Just adding some more notes:
Microsoft.VisualStudio.PackageGroup.TestTools.Core
but as there are not current references to that method my guess is we no longer need it for that.Seems like the latest guidance for referencing MSBuild programmatically is to use nuget packages.
@Tiberriver256 well, yes, but that would require to restructure the whole generator concept, I fear. The need for testing through MsBuild is getting less and less important, so I would not invest that much time on it. So I think we should stick to executing MsBuild.exe
, but get the path in a more flexible way.
Sounds good 👍
A new method for locating MSBuild is provided from a nuget package called Microsoft.Build.Locator
. Documentation is provided here.
It supports finding MSBuild installed as part of the dotnet SDK in addition to Visual Studio. The only caveat is provided in this warning:
The Microsoft.Build.Locator package contains assemblies for .NET Framework and .NET Core (also applicable to .NET 5 and later). In a .NET Framework application, the .NET Framework version of Microsoft.Build.Locator is used, and in a .NET Core application, the .NET Core version is used. However, the .NET Core version can only find instances of MSBuild built with .NET Core, the MSBuild used by dotnet.exe in .NET SDK installations, not Visual Studio installations or Visual Studio Build Tools installations. The .NET Framework version of Microsoft.Build.Locator can only see Visual Studio installations, Visual Studio Build Tools installations, not .NET SDK installations. Therefore, it might be necessary to build a tool in two different target framework configurations to target both.
The need for testing through MsBuild is getting less and less important.
As long as Visual Studio runs on .NET Framework and uses the integrated MSBuild, this is important.
Specially the assembly loading is different so every third party dependency can make problems.
As long as Visual Studio runs on .NET Framework and uses the integrated MSBuild, this is important.
Sure. That's what I wanted to say with "less and less" - hopefully VS will also change its behavior at some point... :)
Specially the assembly loading is different so every third party dependency can make problems.
Do you mean especially generator plugins? Or have you seen problems with normal lib dependencies as well?
Fixed by #75
Unfortunately this solution does not work. Now as I work on "portability" tests of system testing and want to test the build with MsBuild, it turned out:
Microsoft.Build.Locator
, in VisualStudioInstance.MSBuildPath
only returns the folder of MsBuild, not the executable itself.C:\Program Files\dotnet\sdk\6.0.321
, but that does not contain an msbuild.exe
executable, but only an msbuild.dll
, that is not usable for our testsmsbuild.exe
at all. Reading back what @ajeckmans answered, if you install Rider, it actually installs an own version of msbuild.exe
, just like Visual Studio does.Conclusion: I will undo this change and revert to a solution that finds msbuild.exe
from VS, if you have one, otherwise it requires you to set an environment variable with the msbuild path or just make sure that msbuild
is in the PATH.
Sounds good. Bummer on the sdk only including a dll. I'll take another stab at this but sounds like we should prioritize getting tests running in the CI first before we go again so I don't drop more broken stuff in.
@Tiberriver256 yes, this is my plan with #82. I made the fix there and as a result now it works locally (on a machine with VS). I will try to setup the CI tomorrow.
Next to vswhere, when it fails to locate an installation, we should probably use https://www.nuget.org/packages/JetBrains.Rider.PathLocator (which is https://github.com/JetBrains/RiderSourceCodeAccess/tree/main/Source/RiderSourceCodeAccess/Private/RiderPathLocator) to locate the installation of Rider. If one is found we can use the packaged msbuild.exe. It is in a fixed path within that folder at /tools/MSBuild/Current/Bin/msbuild.exe
@ajeckmans I will do that. Does Rider adds this folder to the PATH maybe? (or at least for the scope of the test execution process)?
I have no idea.
Fixed as part of #82. The Rider heuristics are not added yet.
Goal
Make contributing to Reqnroll codebase easier for developers who are not using Visual Studio
Additional Information
See discussion here.
Note on background from @SabotageAndi
Proposed direction from @gasparnagy
I also dug into this a bit, and it seems we technically don't need Visual Studio to get VSWhere. There are some alternative ways to install it, one of which is a nuget package.
Before that, though, I'm going to try and document in this bug discussion exactly what tests use it and why.