{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/msbuild/issues/1461","repository_url":"https://api.github.com/repos/Microsoft/msbuild","labels_url":"https://api.github.com/repos/Microsoft/msbuild/issues/1461/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/msbuild/issues/1461/comments","events_url":"https://api.github.com/repos/Microsoft/msbuild/issues/1461/events","html_url":"https://github.com/Microsoft/msbuild/issues/1461","id":194474612,"number":1461,"title":"SPEC: Visual Studio & Toolset Discovery","user":{"login":"AndyGerlicher","id":9847849,"avatar_url":"https://avatars.githubusercontent.com/u/9847849?v=3","gravatar_id":"","url":"https://api.github.com/users/AndyGerlicher","html_url":"https://github.com/AndyGerlicher","followers_url":"https://api.github.com/users/AndyGerlicher/followers","following_url":"https://api.github.com/users/AndyGerlicher/following{/other_user}","gists_url":"https://api.github.com/users/AndyGerlicher/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyGerlicher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyGerlicher/subscriptions","organizations_url":"https://api.github.com/users/AndyGerlicher/orgs","repos_url":"https://api.github.com/users/AndyGerlicher/repos","events_url":"https://api.github.com/users/AndyGerlicher/events{/privacy}","received_events_url":"https://api.github.com/users/AndyGerlicher/received_events","type":"User","site_admin":false},"labels":[{"id":461826677,"url":"https://api.github.com/repos/Microsoft/msbuild/labels/Priority%201","name":"Priority 1","color":"e99695","default":false}],"state":"open","locked":false,"assignee":{"login":"AndyGerlicher","id":9847849,"avatar_url":"https://avatars.githubusercontent.com/u/9847849?v=3","gravatar_id":"","url":"https://api.github.com/users/AndyGerlicher","html_url":"https://github.com/AndyGerlicher","followers_url":"https://api.github.com/users/AndyGerlicher/followers","following_url":"https://api.github.com/users/AndyGerlicher/following{/other_user}","gists_url":"https://api.github.com/users/AndyGerlicher/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyGerlicher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyGerlicher/subscriptions","organizations_url":"https://api.github.com/users/AndyGerlicher/orgs","repos_url":"https://api.github.com/users/AndyGerlicher/repos","events_url":"https://api.github.com/users/AndyGerlicher/events{/privacy}","received_events_url":"https://api.github.com/users/AndyGerlicher/received_events","type":"User","site_admin":false},"assignees":[{"login":"AndyGerlicher","id":9847849,"avatar_url":"https://avatars.githubusercontent.com/u/9847849?v=3","gravatar_id":"","url":"https://api.github.com/users/AndyGerlicher","html_url":"https://github.com/AndyGerlicher","followers_url":"https://api.github.com/users/AndyGerlicher/followers","following_url":"https://api.github.com/users/AndyGerlicher/following{/other_user}","gists_url":"https://api.github.com/users/AndyGerlicher/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyGerlicher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyGerlicher/subscriptions","organizations_url":"https://api.github.com/users/AndyGerlicher/orgs","repos_url":"https://api.github.com/users/AndyGerlicher/repos","events_url":"https://api.github.com/users/AndyGerlicher/events{/privacy}","received_events_url":"https://api.github.com/users/AndyGerlicher/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/Microsoft/msbuild/milestones/11","html_url":"https://github.com/Microsoft/msbuild/milestone/11","labels_url":"https://api.github.com/repos/Microsoft/msbuild/milestones/11/labels","id":2172287,"number":11,"title":"MSBuild 15.1 RC.3","description":"","creator":{"login":"AndyGerlicher","id":9847849,"avatar_url":"https://avatars.githubusercontent.com/u/9847849?v=3","gravatar_id":"","url":"https://api.github.com/users/AndyGerlicher","html_url":"https://github.com/AndyGerlicher","followers_url":"https://api.github.com/users/AndyGerlicher/followers","following_url":"https://api.github.com/users/AndyGerlicher/following{/other_user}","gists_url":"https://api.github.com/users/AndyGerlicher/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyGerlicher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyGerlicher/subscriptions","organizations_url":"https://api.github.com/users/AndyGerlicher/orgs","repos_url":"https://api.github.com/users/AndyGerlicher/repos","events_url":"https://api.github.com/users/AndyGerlicher/events{/privacy}","received_events_url":"https://api.github.com/users/AndyGerlicher/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":2,"state":"open","created_at":"2016-12-02T22:02:42Z","updated_at":"2016-12-08T23:38:56Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-12-08T23:38:56Z","updated_at":"2016-12-09T17:52:21Z","closed_at":null,"body":"Currently the logic to find out where MSBuild is located has grown in complexity and is not coupled to Visual Studio discovery. Unfortunately these two are more intermingled than we originally thought and must be revisited to fix some issues.\r\n\r\nThis discovery is required for MSBuild to operate because depending on environment (or mode) MSBuild behaves slightly different for things like extensions path and other items defined in the toolset.\r\n\r\nI am proposing that we detect and operate in one of three modes: `VS`, `Standalone`, and `Disconnected`. The logic to discover the environment could be as follows:\r\n\r\n```C#\r\nEntry = Entry point process exe\r\nDevConsole = Directory Exists (%VSINSTALLDIR%) && VisualStudioVersion == '15.0'\r\n\r\nif (Entry == 'devenv.exe')\r\n{ // Case #1\r\n  Mode = 'VS'\r\n  ToolsPath = Entry.Directory\\..\\..\\MSBuild\\15.0\\Bin\\\r\n  ToolsPath64 = %ToolsPath%\\Amd64\r\n  MSBuildExtensionsPath = Entry.Directory\\..\\..\\MSBuild\r\n  VisualStudioDir = Entry.Directory\\..\\..\\\r\n}\r\nif (Entry == 'MSBuild.exe')\r\n{\r\n  if (Entry.Directory like '%\\MSBuild\\15.0\\Bin\\%')\r\n  { // Case #2\r\n    Mode = 'VS'\r\n    ToolsPath = Entry.Directory  // Note: We may be already in Amd64\\MSBuild.exe. Must account for this.\r\n    ToolsPath64 = %ToolsPath%\\Amd64\r\n    MSBuildExtensionsPath = Entry.Directory\\..\\..\\\r\n    VisualStudioPath = Entry.Directory\\..\\..\\..\\\r\n  }\r\n  else\r\n  { // Case #3\r\n    Mode = 'Standalone'\r\n    ToolsPath = Entry.Directory\r\n    ToolsPath64 = Entry.Directory  // 64 not supported\r\n    MSBuildExtensionsPath = Entry.Directory\r\n    VisualStudioPath = null\r\n  }\r\n}\r\n\r\nif (Entry != MSBuild && Entry != VS)\r\n{\r\n    if (Entry.Directory like '%\\MSBuild\\15.0\\Bin\\%)\r\n    {\r\n      Mode = 'VS',  Case #2      \r\n    }\r\n    if (File Exists: Entry.Directory\\'MSBuild.exe' )\r\n    {\r\n      Mode = 'Standalone', Case #3   // Even in DevConsole\r\n    }\r\n    if (NOT File Exists: Entry.Directory\\'MSBuild.exe' )\r\n    {\r\n      if (DevConsole)\r\n      { // Case #4\r\n        Mode = 'VS\r\n        ToolsPath = DevConsole.VSPath\\MSBuild\\15.0\\Bin\r\n        MSBuildExtensionsPath = DevConsole.VSPath\\MSBuild\r\n        VisualStudioPath = DevConsole.VSPath        \r\n      }\r\n      else if (VS Setup COM API)\r\n      {\r\n        Mode = 'VS', Case #4\r\n        if (VSSetup.Count > 1) Warn\r\n      }\r\n      else\r\n      {\r\n        Mode = 'None'\r\n      }\r\n    }\r\n}\r\n```\r\n\r\nPrinciples in each Mode:\r\n`VS`: \r\n* Toolsets are read from the process called. If you call into MSBuild.exe it should use the toolset that ships with that instance of Visual Studio\r\n* Extensions path set to `%VSINSTALLDIR%\\MSBuild` path with fallback to `c:\\Program Files (x86)\\MSBuild`.\r\n\r\n`Standalone`:\r\n* Toolsets are read locally (or hard coded locally in .NET Core).\r\n* Should never be aware of Visual Studio knowledge or SDKs.\r\n\r\n`None`:\r\n* This is the case where you reference (for example) Microsoft.Build.dll. Very few things should work.\r\n* Toolsets not read locally, only fallback to registry\r\n\r\n\r\nAction items:\r\n\r\n- [ ] Implement spec in `BuildEnvironmentHelper.cs`.\r\n- [ ] Add warning when more than once instance of Visual Studio is found using the Setup COM API.\r\n- [ ] When in `None` mode, ensure that the toolset reader does not throw. Likely nothing will build successfully, but for example the construction API should function. No project evaluation or build will work. \r\n- [ ] Potential idea: Publish NuGet package to help a standalone app find MSBuild. This would check if we're in DevConsole or use the Setup COM API to find VS and add AssemblyLoad logic to the current AppDomain to find Microsoft.Build.*.dll."},"comment":{"url":"https://api.github.com/repos/Microsoft/msbuild/issues/comments/266077325","html_url":"https://github.com/Microsoft/msbuild/issues/1461#issuecomment-266077325","issue_url":"https://api.github.com/repos/Microsoft/msbuild/issues/1461","id":266077325,"user":{"login":"AndyGerlicher","id":9847849,"avatar_url":"https://avatars.githubusercontent.com/u/9847849?v=3","gravatar_id":"","url":"https://api.github.com/users/AndyGerlicher","html_url":"https://github.com/AndyGerlicher","followers_url":"https://api.github.com/users/AndyGerlicher/followers","following_url":"https://api.github.com/users/AndyGerlicher/following{/other_user}","gists_url":"https://api.github.com/users/AndyGerlicher/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyGerlicher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyGerlicher/subscriptions","organizations_url":"https://api.github.com/users/AndyGerlicher/orgs","repos_url":"https://api.github.com/users/AndyGerlicher/repos","events_url":"https://api.github.com/users/AndyGerlicher/events{/privacy}","received_events_url":"https://api.github.com/users/AndyGerlicher/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T17:52:21Z","updated_at":"2016-12-09T17:52:21Z","body":"Sorry about the bad pseudocode, quick attempt to capture what we did on the whiteboard :)\r\n\r\nI would say VS version == 15.0 (CurrentVisualStudioVersion). If VS version is 16 or 17 and MSBuild is built for 15 we should probably ignore it?\r\n\r\nCase 4 is from the DevConsole, so we find VS by the environment variable.\r\n\r\nThe case-3 even in devconsole was a note because we had a discussion if we should do something different. But in that case you included an MSBuild.exe (or .dll) so you're intending to be in Standalone mode. So in that case we should not know about VS toolsets. So we would ignore VSINSTALLDIR, etc."}}
{"actor":{"display_login":"AndyGerlicher"}}