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

Unable to find 15.0 toolset in a project with MSBuild in it's name. #2194

Closed
srivatsn opened this issue Jun 8, 2017 · 10 comments
Closed

Unable to find 15.0 toolset in a project with MSBuild in it's name. #2194

srivatsn opened this issue Jun 8, 2017 · 10 comments

Comments

@srivatsn
Copy link
Contributor

srivatsn commented Jun 8, 2017

Repro steps:

  • Create a project called "MSBuildTest" (or something with msbuild in the name) and reference the Microsoft.Build package.
  • Add the following code
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += (sender, eventArgs) =>
            {
                string msbuildPath = @"C:\Program Files (x86)\Microsoft Visual Studio\D15PreRel\MSBuild\15.0\Bin\";
                var targetAssembly = Path.Combine(msbuildPath, new AssemblyName(eventArgs.Name).Name + ".dll");
                return File.Exists(targetAssembly) ? Assembly.LoadFrom(targetAssembly) : null;
            };
            Run();
        }

        private static void Run()
        {
            ProjectCollection collection = new ProjectCollection();
            var project = collection.LoadProject(@"ConsoleApp.csproj");
        }
  • Make sure there's a ConsoleApp.csproj which has ToolsVersion="15.0" in it.

Expected: The project should loaded fine.

Found: Throws

Microsoft.Build.Exceptions.InvalidProjectFileException: 'The tools version "15.0" is unrecognized. Available tools versions are "2.0", "3.5", "4.0".  ConsoleApp.csproj'

This is because BuildEnvironmentHelper tries to ascertain the mode in which msbuild is launched and one of the checks it does is to look at the process name and sees if it contains “MSBuild”. In this case, it think the BuildMode is Standalone and doesn't read msbuild.exe.config and hence doesn't get the 15.0 toolset.

srivatsn added a commit to srivatsn/ProjectSimplifier that referenced this issue Jun 8, 2017
@rainersigwald
Copy link
Member

Relevant code is here

Path.GetFileNameWithoutExtension(processName)?
  .IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0);

Could be .Equals(s, StringComparison.OrdinalIgnoreCase) for this case, but not the test-runner cases. Maybe we could switch it up to be a regex match?

@rainersigwald
Copy link
Member

I hoped that setting the environment variable MSBUILD_EXE_PATH would work around this, but it doesn't, because that always defaults to standalone mode, which is the problem here.

@rainersigwald rainersigwald added this to the MSBuild 15.3 milestone Jun 8, 2017
@AndyGerlicher AndyGerlicher modified the milestones: MSBuild 15 "foundation update" 2, MSBuild 15.3 Jun 19, 2017
@williamb1024
Copy link

The same problem occurs if the process's image name contains DEVENV or BLEND.

@kzu
Copy link
Contributor

kzu commented Jul 3, 2017

Running

Microsoft Visual Studio Enterprise 2017 Int Preview
Version 15.3.0 Preview 3.0 [26620.0.d15rel]
VisualStudio.15.IntPreview/15.3.0-pre.3.0+26620.0.d15rel

and still seeing this in an xunit test running through the xunit.runner.visualstudio runner from within the VSTS test explorer.

@jairbubbles
Copy link

jairbubbles commented Jul 26, 2017

I stumbled into it too... thanks for reporting it.

I guess the first thing you do to test that lib is to create a MsBuild test application with MsBuild in the name...

@weltkante
Copy link

While the IsProcessInList heuristic is broader than it needs to be, the actual problem is that most of the TryFromXXX methods rely on a single heuristic and then return a BuildEnvironment without double checking if it actually is a valid one. This causes the calling loop to break the chain of try-methods and return an invalid build environment. Since heuristics can always have false-positives, validating the guess would be a more robust fix than just making IsProcessInList more strict.

@DustinCampbell
Copy link
Member

I've run into this too. Great find!

@DustinCampbell
Copy link
Member

Forgot about this problem and just ran into it again. 😄

@jairbubbles
Copy link

Well maybe we should add a link to this issue in the exception 😄

@DustinCampbell
Copy link
Member

Well, the exception is that it can't find the toolset, so that's a bit heavy handed. 😸

@AndyGerlicher AndyGerlicher modified the milestones: MSBuild 15.5, After 15 Sep 28, 2017
rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Feb 8, 2018
Fixes the problem where a program using the MSBuild API and
containing the string "MSBuild" in its name was incorrectly detected as
running in MSBuild.exe in standalone mode.

Fixes dotnet#2194.
rainersigwald added a commit that referenced this issue Feb 9, 2018
Fixes the problem where a program using the MSBuild API and
containing the string "MSBuild" in its name was incorrectly detected as
running in MSBuild.exe in standalone mode.

Fixes #2194.
scotternst59 added a commit to scotternst59/try-convert-Csharp-angular that referenced this issue Sep 29, 2022
brendasmith8 pushed a commit to brendasmith8/try-convert that referenced this issue Oct 18, 2022
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants