forked from dotnet/project-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTargetFrameworkMoniker.vb
107 lines (78 loc) · 3.59 KB
/
TargetFrameworkMoniker.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
' Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.
Imports System.ComponentModel
Imports System.Runtime.Versioning
Imports EnvDTE
Imports Microsoft.VisualStudio.Shell.Interop
Namespace Microsoft.VisualStudio.Editors.PropertyPages
''' <summary>
''' Represents a target framework moniker and can be placed into a control
''' </summary>
Friend Class TargetFrameworkMoniker
''' <summary>
''' Stores the target framework moniker
''' </summary>
Private ReadOnly _moniker As String
''' <summary>
''' Stores the display name of the target framework moniker
''' </summary>
Private ReadOnly _displayName As String
''' <summary>
''' Constructor that uses the target framework moniker and display name provided by DTAR
''' </summary>
Public Sub New(moniker As String, displayName As String)
_moniker = moniker
_displayName = displayName
End Sub
''' <summary>
''' Gets the target framework moniker
''' </summary>
Public ReadOnly Property Moniker As String
Get
Return _moniker
End Get
End Property
''' <summary>
''' Use the display name provided by DTAR for the string display
''' </summary>
Public Overrides Function ToString() As String
Return _displayName
End Function
''' <summary>
''' Gets the supported target framework monikers from DTAR
''' </summary>
Public Shared Function GetSupportedTargetFrameworkMonikers(
frameworkMultiTargeting As IVsFrameworkMultiTargeting,
project As Project,
converter As TypeConverter) As IReadOnlyList(Of TargetFrameworkMoniker)
Dim provider = GetSupportedTargetFrameworksProvider(frameworkMultiTargeting, project, converter)
Dim moniker As [Property] = project.Properties.Item(ApplicationPropPage.Const_TargetFrameworkMoniker)
Dim framework = New FrameworkName(CStr(moniker.Value))
Return provider.GetSupportedTargetFrameworks(framework)
End Function
Private Shared Function GetSupportedTargetFrameworksProvider(
frameworkMultiTargeting As IVsFrameworkMultiTargeting,
project As Project,
converter As TypeConverter) As ISupportedTargetFrameworksProvider
' CPS provides a type converter via a project property that
' returns the supported frameworks, use them if available.
If (converter IsNot Nothing) Then
Return New TypeConverterTargetProvider(converter)
End If
' Is this Web Application project?
If IsWebProject(project) Then
Return New WebFrameworkMultiTargetProvider(frameworkMultiTargeting)
End If
' Otherwise, a legacy project
Return New FrameworkMultiTargetProvider(frameworkMultiTargeting)
End Function
Private Shared Function IsWebProject(project As Project) As Boolean
' Determine if the project is a WAP (Web Application Project).
For i As Integer = 1 To project.Properties.Count
If project.Properties.Item(i).Name.StartsWith("WebApplication.") Then
Return True
End If
Next
Return False
End Function
End Class
End Namespace