-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Add profile generators for Visual Studio #7774
Merged
DHowett
merged 16 commits into
microsoft:main
from
trippwill:dev/charleswillis3/vsdevgenerators
Sep 15, 2021
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e9e91c5
Add profile generators for Visual Studio
a70adbd
Fix Code Formatting
14cc46d
Cache QueryInstances results
932e818
Use smart pointers during VS Setup enumeration
a3f032b
Merge branch 'main' of https://github.com/microsoft/terminal into mic…
b227614
Merge branch 'microsoft-main' into dev/charleswillis3/vsdevgenerators
b7cecf3
Enable VS Developer Shell generators
96f257c
Fix spelling errors
43ff39f
PR Feedback
4cc8104
zadjii-msft PR feedback
97bec05
SetupConfiguration feedback
7571615
Custom Profile Guid, fewer exceptions
e7b2b43
Merge remote-tracking branch 'origin/main' into HEAD
DHowett a0d01b8
Fix code format
DHowett f33b486
Remove <MUST BE REMOVED> lines from nuget.config
DHowett c750e07
Remove the BOM from NuGet.Config (reduce diff)
DHowett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ iosfwd | |
IPackage | ||
IPeasant | ||
isspace | ||
ISetup | ||
IStorage | ||
istream | ||
IStringable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2577,6 +2577,7 @@ VREDRAW | |
vsc | ||
vscprintf | ||
VSCROLL | ||
vsdevshell | ||
vsinfo | ||
vsnprintf | ||
vso | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/cascadia/TerminalSettingsModel/BaseVisualStudioGenerator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "BaseVisualStudioGenerator.h" | ||
#include "DefaultProfileUtils.h" | ||
|
||
using namespace Microsoft::Terminal::Settings::Model; | ||
using namespace winrt::Microsoft::Terminal::Settings::Model; | ||
|
||
std::vector<Profile> BaseVisualStudioGenerator::GenerateProfiles() | ||
{ | ||
std::vector<Profile> profiles; | ||
|
||
// There's no point in enumerating valid Visual Studio instances more than once, | ||
// so cache them for use by both Visual Studio profile generators. | ||
if (!BaseVisualStudioGenerator::hasQueried) | ||
{ | ||
instances = VsSetupConfiguration::QueryInstances(); | ||
hasQueried = true; | ||
} | ||
|
||
for (auto const& instance : BaseVisualStudioGenerator::instances) | ||
{ | ||
try | ||
{ | ||
if (!IsInstanceValid(instance)) | ||
continue; | ||
|
||
auto DevShell{ CreateProfile(GetProfileGuidSeed(instance)) }; | ||
DevShell.Name(GetProfileName(instance)); | ||
DevShell.Commandline(GetProfileCommandLine(instance)); | ||
DevShell.StartingDirectory(instance.GetInstallationPath()); | ||
DevShell.Icon(GetProfileIconPath()); | ||
|
||
profiles.emplace_back(DevShell); | ||
} | ||
CATCH_LOG(); | ||
} | ||
|
||
return profiles; | ||
} | ||
|
||
Profile BaseVisualStudioGenerator::CreateProfile(const std::wstring_view seed) | ||
{ | ||
const winrt::guid profileGuid{ Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, | ||
gsl::as_bytes(gsl::make_span(seed))) }; | ||
|
||
auto newProfile = winrt::make_self<implementation::Profile>(profileGuid); | ||
newProfile->Origin(OriginTag::Generated); | ||
|
||
return *newProfile; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/cascadia/TerminalSettingsModel/BaseVisualStudioGenerator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*++ | ||
Copyright (c) Microsoft Corporation | ||
Licensed under the MIT license. | ||
|
||
Module Name: | ||
- BaseVisualStudioGenerator | ||
|
||
Abstract: | ||
- Base generator for Visual Studio Developer shell profiles | ||
|
||
Author(s): | ||
- Charles Willis - October 2020 | ||
|
||
--*/ | ||
|
||
#pragma once | ||
|
||
#include "IDynamicProfileGenerator.h" | ||
#include "VsSetupConfiguration.h" | ||
|
||
namespace Microsoft::Terminal::Settings::Model | ||
{ | ||
class BaseVisualStudioGenerator : public IDynamicProfileGenerator | ||
{ | ||
virtual bool IsInstanceValid(const VsSetupConfiguration::VsSetupInstance instance) const = 0; | ||
virtual std::wstring GetProfileName(const VsSetupConfiguration::VsSetupInstance instance) const = 0; | ||
virtual std::wstring GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance instance) const = 0; | ||
virtual std::wstring GetProfileGuidSeed(const VsSetupConfiguration::VsSetupInstance instance) const = 0; | ||
virtual std::wstring GetProfileIconPath() const = 0; | ||
|
||
// Inherited via IDynamicProfileGenerator | ||
virtual std::wstring_view GetNamespace() override = 0; | ||
std::vector<winrt::Microsoft::Terminal::Settings::Model::Profile> GenerateProfiles() override; | ||
|
||
private: | ||
inline static bool hasQueried = false; | ||
inline static std::vector<VsSetupConfiguration::VsSetupInstance> instances; | ||
|
||
winrt::Microsoft::Terminal::Settings::Model::Profile CreateProfile(const std::wstring_view instanceId); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "VsDevCmdGenerator.h" | ||
|
||
using namespace Microsoft::Terminal::Settings::Model; | ||
|
||
std::wstring VsDevCmdGenerator::GetProfileName(const VsSetupConfiguration::VsSetupInstance instance) const | ||
{ | ||
std::wstring name{ L"Developer Command Prompt for VS " }; | ||
name.append(instance.GetProfileNameSuffix()); | ||
return name; | ||
} | ||
|
||
std::wstring VsDevCmdGenerator::GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance instance) const | ||
{ | ||
std::wstring commandLine{ L"cmd.exe /k \"" + instance.GetDevCmdScriptPath() + L"\"" }; | ||
|
||
return commandLine; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*++ | ||
Copyright (c) Microsoft Corporation | ||
Licensed under the MIT license. | ||
|
||
Module Name: | ||
- VsDevCmdGenerator | ||
|
||
Abstract: | ||
- Dynamic profile generator for Visual Studio Developer Command Prompt | ||
|
||
Author(s): | ||
- Charles Willis - October 2020 | ||
|
||
--*/ | ||
|
||
#pragma once | ||
#include "BaseVisualStudioGenerator.h" | ||
|
||
namespace Microsoft::Terminal::Settings::Model | ||
{ | ||
class VsDevCmdGenerator : public BaseVisualStudioGenerator | ||
{ | ||
public: | ||
VsDevCmdGenerator() = default; | ||
~VsDevCmdGenerator() = default; | ||
|
||
std::wstring_view GetNamespace() override | ||
{ | ||
return std::wstring_view{ L"Windows.Terminal.VisualStudio.CommandPrompt" }; | ||
} | ||
|
||
inline bool IsInstanceValid(const VsSetupConfiguration::VsSetupInstance instance) const override | ||
{ | ||
// We only support version of VS from 15.0. | ||
// Per heaths: The [ISetupConfiguration] COM server only supports Visual Studio 15.0 and newer anyway. | ||
// Eliding the version range will improve the discovery performance by not having to parse or compare the versions. | ||
return true; | ||
} | ||
|
||
inline std::wstring GetProfileGuidSeed(const VsSetupConfiguration::VsSetupInstance instance) const override | ||
{ | ||
return L"VsDevCmd" + instance.GetInstanceId(); | ||
} | ||
|
||
inline std::wstring GetProfileIconPath() const override | ||
{ | ||
return L"ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png"; | ||
} | ||
|
||
std::wstring GetProfileName(const VsSetupConfiguration::VsSetupInstance instance) const override; | ||
std::wstring GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance instance) const override; | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: tabbing off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not worried about it, becuase it needs to be removed before this can merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zadjii-msft , @DHowett How do I get Microsoft.VisualStudio.Setup.Configuration.Native served from your single nuget source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna also /cc @miniksa since he's most familiar with the CI stuff and can probably get to this before me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During conflict resolution, you can finally back this one on out 😄