@@ -91,6 +91,12 @@ public sealed class LINQBridgeVsPackage : Package
9191 private static readonly XDocument MicrosoftCommonTargetDocument
9292 = XDocument . Load ( Locations . MicrosoftCommonTargetFileNamePath ) ;
9393
94+ private static readonly XDocument MicrosoftCommonTargetX64Document
95+ = XDocument . Load ( Locations . MicrosoftCommonTargetX64FileNamePath ) ;
96+
97+ private static readonly XDocument MicrosoftCommonTarget45Document
98+ = XDocument . Load ( Locations . MicrosoftCommonTarget45FileNamePath ) ;
99+
94100 public DTE2 ApplicationObject
95101 {
96102 get
@@ -170,7 +176,11 @@ private void HandleVisualStudioShutDown()
170176 if ( Process . GetProcessesByName ( VisualStudioProcessName ) . Length > 1 ) return ;
171177
172178 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 ) ;
174184
175185 PackageConfigurator . IsEnvironmentConfigured = false ;
176186 }
@@ -191,7 +201,11 @@ private void OnStartupComplete()
191201 _dteEvents . OnStartupComplete -= OnStartupComplete ;
192202 _dteEvents = null ;
193203
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 ) ;
195209
196210 Log . Write ( "OnStartupComplete End" ) ;
197211
@@ -202,58 +216,9 @@ private void OnStartupComplete()
202216 }
203217 }
204218
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+
226220
227- if ( MicrosoftCommonTargetDocument . Root == null || GetTargetImportNode ( ) != null ) return ;
228221
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- }
257222
258223
259224 #endregion
0 commit comments