@@ -13,7 +13,7 @@ internal static class PackageConfigurator
1313 {
1414 private static string _vsVersion ;
1515 private static readonly string CurrentAssemblyVersion = FileVersionInfo . GetVersionInfo ( Assembly . GetExecutingAssembly ( ) . Location ) . FileVersion ;
16- private static readonly bool IsFramework45Installed = File . Exists ( Locations . DotNet45FrameworkPath ) ;
16+ private static readonly bool IsFramework45Installed = Directory . Exists ( Locations . DotNet45FrameworkPath ) ;
1717
1818 private static string LINQBridgeVsExtensionVersion
1919 {
@@ -22,13 +22,13 @@ private static string LINQBridgeVsExtensionVersion
2222 using ( var key = Registry . CurrentUser . OpenSubKey ( GetRegistryKeyWithVersion ( Resources . ProductVersion ) ) )
2323 {
2424 if ( key == null ) return string . Empty ;
25-
25+
2626 var value = key . GetValue ( "LINQBridgeVsVersion" ) ;
2727
2828 if ( value != null )
2929 return value . ToString ( ) ;
3030 }
31-
31+
3232
3333 return string . Empty ;
3434 }
@@ -115,6 +115,8 @@ private static void SetEnvironment()
115115 return ;
116116 }
117117
118+ SetPermissions ( ) ;
119+
118120
119121 //Copy the BridgeBuildTask.targets to the default .NET 4.0v framework location
120122 File . Copy ( Locations . LinqBridgeTargetFileNamePath , Path . Combine ( Locations . DotNet40FrameworkPath , Locations . LinqBridgeTargetFileName ) , true ) ;
@@ -133,7 +135,6 @@ private static void SetEnvironment()
133135 Path . Combine ( Locations . DotNet45FrameworkPath , Locations . LinqBridgeTargetFileName ) , true ) ;
134136 Log . Write ( "LinqBridge Targets copied to {0} " , Locations . DotNet45FrameworkPath ) ;
135137 }
136- SetPermissions ( ) ;
137138
138139 Log . Write ( "Setting IsEnvironmentConfigured to True" ) ;
139140 IsEnvironmentConfigured = true ;
@@ -164,19 +165,11 @@ private static void SetPermissions()
164165 Log . Write ( "SetPermission Starts" ) ;
165166 var processOutputs = new StringBuilder ( ) ;
166167
167- var icaclsProcess = new Process
168+ var icaclsProcess45Folder = new Process
168169 {
169- StartInfo = { UseShellExecute = false , CreateNoWindow = true , WindowStyle = ProcessWindowStyle . Hidden , RedirectStandardError = true , RedirectStandardInput = true , RedirectStandardOutput = true , FileName = "icacls.exe" , Arguments = Locations . IcaclsArguments }
170+ StartInfo = { UseShellExecute = false , CreateNoWindow = true , WindowStyle = ProcessWindowStyle . Hidden , RedirectStandardError = true , RedirectStandardInput = true , RedirectStandardOutput = true , FileName = "icacls.exe" , Arguments = Locations . IcaclsArguments45 , LoadUserProfile = true }
170171 } ;
171172
172- var icaclsProcess45 = new Process
173- {
174- StartInfo = { UseShellExecute = false , CreateNoWindow = true , WindowStyle = ProcessWindowStyle . Hidden , RedirectStandardError = true , RedirectStandardInput = true , RedirectStandardOutput = true , FileName = "icacls.exe" , Arguments = Locations . IcaclsArguments45 }
175- } ;
176- var icaclsProcessX64 = new Process
177- {
178- StartInfo = { UseShellExecute = false , CreateNoWindow = true , WindowStyle = ProcessWindowStyle . Hidden , RedirectStandardError = true , FileName = "icacls.exe" , Arguments = Locations . IcaclsArgumentsX64 , LoadUserProfile = true }
179- } ;
180173 var icaclsProcessCommonTarget = new Process
181174 {
182175 StartInfo = { UseShellExecute = false , CreateNoWindow = true , WindowStyle = ProcessWindowStyle . Hidden , RedirectStandardError = true , RedirectStandardInput = true , RedirectStandardOutput = true , FileName = "icacls.exe" , Arguments = Locations . IcaclsArgumentsCommonTarget , LoadUserProfile = true }
@@ -186,6 +179,12 @@ private static void SetPermissions()
186179 StartInfo = { UseShellExecute = false , CreateNoWindow = true , WindowStyle = ProcessWindowStyle . Hidden , RedirectStandardError = true , RedirectStandardInput = true , RedirectStandardOutput = true , FileName = "icacls.exe" , Arguments = Locations . IcaclsArgumentsX64CommonTarget , LoadUserProfile = true }
187180 } ;
188181
182+ var icaclsProcess45CommonTarget = new Process
183+ {
184+ StartInfo = { UseShellExecute = false , CreateNoWindow = true , WindowStyle = ProcessWindowStyle . Hidden , RedirectStandardError = true , RedirectStandardInput = true , RedirectStandardOutput = true , FileName = "icacls.exe" , Arguments = Locations . IcaclsArguments45CommonTarget , LoadUserProfile = true }
185+ } ;
186+
187+ #region [ Take Own ]
189188 var takeownProcess = Process . Start ( "takeown" , String . Format ( "/f {0}" , Locations . MicrosoftCommonTargetFileNamePath ) ) ;
190189 if ( takeownProcess != null ) takeownProcess . WaitForExit ( ) ;
191190
@@ -196,47 +195,54 @@ private static void SetPermissions()
196195
197196 if ( takeownProcessx64 != null ) takeownProcessx64 . WaitForExit ( ) ;
198197 }
199- icaclsProcess . Start ( ) ;
198+ if ( IsFramework45Installed )
199+ {
200+ var takeownProcess45 = Process . Start ( "takeown" ,
201+ String . Format ( "/f \" {0}\" " , Locations . DotNet45FrameworkPath ) ) ;
202+
203+ if ( takeownProcess45 != null ) takeownProcess45 . WaitForExit ( ) ;
204+ }
205+ #endregion
206+
200207
201208 if ( IsFramework45Installed )
202- icaclsProcess45 . Start ( ) ;
209+ {
210+ icaclsProcess45Folder . Start ( ) ;
211+ icaclsProcess45CommonTarget . Start ( ) ;
212+ }
203213
204214 icaclsProcessCommonTarget . Start ( ) ;
205215
206216 if ( Environment . Is64BitOperatingSystem )
207217 {
208- icaclsProcessX64 . Start ( ) ;
209218 icaclsProcessX64CommonTarget . Start ( ) ;
210- Log . Write ( "Setting Permission to {0} and {1} " , Locations . IcaclsArguments , Locations . IcaclsArgumentsX64 ) ;
211219 Log . Write ( "Setting Permission to {0} and {1} " , Locations . IcaclsArgumentsCommonTarget , Locations . IcaclsArgumentsX64CommonTarget ) ;
212-
213220 }
214221
215222 if ( IsFramework45Installed )
216- icaclsProcess45 . WaitForExit ( ) ;
223+ {
224+ icaclsProcess45Folder . WaitForExit ( ) ;
225+ icaclsProcess45CommonTarget . WaitForExit ( ) ;
226+ }
217227
218- icaclsProcess . WaitForExit ( ) ;
219228 icaclsProcessCommonTarget . WaitForExit ( ) ;
229+
220230 if ( Environment . Is64BitOperatingSystem )
221- {
222- icaclsProcessX64 . WaitForExit ( ) ;
223231 icaclsProcessX64CommonTarget . WaitForExit ( ) ;
224- }
225232
226- if ( icaclsProcess . ExitCode != 0 )
227- processOutputs . AppendLine ( icaclsProcess . StandardOutput . ReadToEnd ( ) ) ;
228- if ( icaclsProcess . ExitCode != 0 )
233+ if ( icaclsProcessCommonTarget . ExitCode != 0 )
229234 processOutputs . AppendLine ( icaclsProcessCommonTarget . StandardOutput . ReadToEnd ( ) ) ;
230235
231- if ( IsFramework45Installed && icaclsProcess . ExitCode != 0 )
232- processOutputs . AppendLine ( icaclsProcess45 . StandardOutput . ReadToEnd ( ) ) ;
236+ if ( IsFramework45Installed && icaclsProcess45CommonTarget . ExitCode != 0 )
237+ processOutputs . AppendLine ( icaclsProcess45CommonTarget . StandardOutput . ReadToEnd ( ) ) ;
238+
239+ if ( IsFramework45Installed && icaclsProcess45Folder . ExitCode != 0 )
240+ processOutputs . AppendLine ( icaclsProcess45Folder . StandardOutput . ReadToEnd ( ) ) ;
233241
234242
235243 if ( Environment . Is64BitOperatingSystem )
236244 {
237- if ( icaclsProcess . ExitCode != 0 )
238- processOutputs . AppendLine ( icaclsProcessX64 . StandardOutput . ReadToEnd ( ) ) ;
239- if ( icaclsProcess . ExitCode != 0 )
245+ if ( icaclsProcessX64CommonTarget . ExitCode != 0 )
240246 processOutputs . AppendLine ( icaclsProcessX64CommonTarget . StandardOutput . ReadToEnd ( ) ) ;
241247 }
242248
0 commit comments