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

VS2022: msbuild can not be located, only Build Tools are installed #3671

Closed
nils-a opened this issue Nov 5, 2021 · 3 comments · Fixed by #3678
Closed

VS2022: msbuild can not be located, only Build Tools are installed #3671

nils-a opened this issue Nov 5, 2021 · 3 comments · Fixed by #3678
Assignees
Labels
Milestone

Comments

@nils-a
Copy link
Member

nils-a commented Nov 5, 2021

As discussed in #3476,
VS2022 BuildTools should be searched in Program Files (x86), too.

@nils-a nils-a added the Bug label Nov 5, 2021
augustoproiete added a commit to augustoproiete-forks/cake-build--cake that referenced this issue Nov 6, 2021
augustoproiete added a commit to augustoproiete-forks/cake-build--cake that referenced this issue Nov 7, 2021
augustoproiete added a commit to augustoproiete-forks/cake-build--cake that referenced this issue Nov 7, 2021
@augustoproiete augustoproiete added this to the v2.0.0 milestone Nov 14, 2021
@augustoproiete augustoproiete self-assigned this Nov 23, 2021
@cake-build-bot
Copy link

🎉 This issue has been resolved in version v2.0.0 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

@DrewRhoades
Copy link

It sure would have been nice to see this fix in a Cake 1.3.1 release. My Cake 1.3.0 build doesn't recognize the VS2022 Build Tools on my build server, and in order to fix it, I have to rework all my build script to be compatible with Cake.Tools 2.0.0, which appears to be non-trivial (I'm currently using the full framework runner). So I'm basically stuck without investing significant effort.

@DrewRhoades
Copy link

In case someone comes behind me looking for a work-around, I basically used a method as suggested here: #3476

I got the MSBuild path using VSWhere:

#tool nuget:?package=vswhere&version=2.8.4

    public FilePath LatestMSBuildPath { get; private set; }

    LatestMSBuildPath = GetLatestMSBuildPath();

    private FilePath GetLatestMSBuildPath()
    {
        var latestMSBuildPath = context.VSWhereLatest(new VSWhereLatestSettings { Products = "*", Requires = "Microsoft.Component.MSBuild"});
        return new FilePath($"{latestMSBuildPath}\\MSBuild\\Current\\Bin\\MSBuild.exe");
    }

And then when compiling for VS2022, I override the ToolPath in my MSBuildSettings:

    private Func<MSBuildSettings, DirectoryPath, MSBuildSettings> GetMSBuildSettings()
    {
        return (msbuildSettings, path) =>
        {
            msbuildSettings
                .WithTarget("Build")

			...

			if (this.VSVersion == MSBuildToolVersion.VS2022)
			{
				context.Information($"MSBuildPath: {this.LatestMSBuildPath}");
				msbuildSettings.ToolPath = this.LatestMSBuildPath;
			}
			
            return msbuildSettings;
        };
    }

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