@@ -91,6 +91,12 @@ public sealed class LINQBridgeVsPackage : Package
91
91
private static readonly XDocument MicrosoftCommonTargetDocument
92
92
= XDocument . Load ( Locations . MicrosoftCommonTargetFileNamePath ) ;
93
93
94
+ private static readonly XDocument MicrosoftCommonTargetX64Document
95
+ = XDocument . Load ( Locations . MicrosoftCommonTargetX64FileNamePath ) ;
96
+
97
+ private static readonly XDocument MicrosoftCommonTarget45Document
98
+ = XDocument . Load ( Locations . MicrosoftCommonTarget45FileNamePath ) ;
99
+
94
100
public DTE2 ApplicationObject
95
101
{
96
102
get
@@ -170,7 +176,11 @@ private void HandleVisualStudioShutDown()
170
176
if ( Process . GetProcessesByName ( VisualStudioProcessName ) . Length > 1 ) return ;
171
177
172
178
Log . Write ( "Disabling LINQBridgeVS. Only one VS instance opened" ) ;
173
- DisableLinqBridge ( ) ;
179
+ PackageConfigurator . DisableLinqBridge ( MicrosoftCommonTargetDocument , Locations . MicrosoftCommonTargetFileNamePath ) ;
180
+ if ( Environment . Is64BitOperatingSystem )
181
+ PackageConfigurator . DisableLinqBridge ( MicrosoftCommonTargetX64Document , Locations . MicrosoftCommonTargetX64FileNamePath ) ;
182
+ if ( PackageConfigurator . IsFramework45Installed )
183
+ PackageConfigurator . DisableLinqBridge ( MicrosoftCommonTarget45Document , Locations . MicrosoftCommonTarget45FileNamePath ) ;
174
184
175
185
PackageConfigurator . IsEnvironmentConfigured = false ;
176
186
}
@@ -191,7 +201,11 @@ private void OnStartupComplete()
191
201
_dteEvents . OnStartupComplete -= OnStartupComplete ;
192
202
_dteEvents = null ;
193
203
194
- EnableLinqBridge ( ) ;
204
+ PackageConfigurator . EnableLinqBridge ( MicrosoftCommonTargetDocument , Locations . MicrosoftCommonTargetFileNamePath ) ;
205
+ if ( Environment . Is64BitOperatingSystem )
206
+ PackageConfigurator . EnableLinqBridge ( MicrosoftCommonTargetX64Document , Locations . MicrosoftCommonTargetX64FileNamePath ) ;
207
+ if ( PackageConfigurator . IsFramework45Installed )
208
+ PackageConfigurator . EnableLinqBridge ( MicrosoftCommonTarget45Document , Locations . MicrosoftCommonTarget45FileNamePath ) ;
195
209
196
210
Log . Write ( "OnStartupComplete End" ) ;
197
211
@@ -202,58 +216,9 @@ private void OnStartupComplete()
202
216
}
203
217
}
204
218
205
- private static void DisableLinqBridge ( )
206
- {
207
- var linqBridgeTargetImportNode = GetTargetImportNode ( ) ;
208
-
209
- if ( linqBridgeTargetImportNode == null ) return ;
210
-
211
- linqBridgeTargetImportNode . Remove ( ) ;
212
-
213
- MicrosoftCommonTargetDocument . Save ( Locations . MicrosoftCommonTargetFileNamePath ) ;
214
-
215
- if ( Environment . Is64BitOperatingSystem )
216
- MicrosoftCommonTargetDocument . Save ( Locations . MicrosoftCommonTarget64FileNamePath ) ;
217
-
218
-
219
- }
220
-
221
-
222
- private static void EnableLinqBridge ( )
223
- {
224
-
225
- var import = XName . Get ( "Import" , "http://schemas.microsoft.com/developer/msbuild/2003" ) ;
219
+
226
220
227
- if ( MicrosoftCommonTargetDocument . Root == null || GetTargetImportNode ( ) != null ) return ;
228
221
229
- // ReSharper disable once AssignNullToNotNullAttribute
230
- var linqBridgeTarget = new XElement ( import , new XAttribute ( "Project" , Path . GetFileName ( Resources . Targets ) ) ) ;
231
-
232
- MicrosoftCommonTargetDocument . Root . Add ( linqBridgeTarget ) ;
233
-
234
-
235
- MicrosoftCommonTargetDocument . Save ( Locations . MicrosoftCommonTargetFileNamePath ) ;
236
-
237
- if ( Environment . Is64BitOperatingSystem )
238
- MicrosoftCommonTargetDocument . Save ( Locations . MicrosoftCommonTarget64FileNamePath ) ;
239
- }
240
-
241
-
242
- private static XElement GetTargetImportNode ( )
243
- {
244
- var namespaceManager = new XmlNamespaceManager ( new NameTable ( ) ) ;
245
- namespaceManager . AddNamespace ( "aw" , "http://schemas.microsoft.com/developer/msbuild/2003" ) ;
246
-
247
- var importProjectNode =
248
- ( IEnumerable )
249
- MicrosoftCommonTargetDocument . XPathEvaluate ( "/aw:Project/aw:Import[@Project='BridgeBuildTask.targets']" ,
250
- namespaceManager ) ;
251
-
252
-
253
- var linqBridgeTargetImportNode = importProjectNode . Cast < XElement > ( ) . FirstOrDefault ( ) ;
254
-
255
- return linqBridgeTargetImportNode ;
256
- }
257
222
258
223
259
224
#endregion
0 commit comments