99#endif
1010using System . IO ;
1111using System . Linq ;
12- using System . Reflection ;
13- using System . Reflection . Emit ;
1412using Microsoft . Build . Experimental . FileAccess ;
1513using Microsoft . Build . Framework ;
1614using Microsoft . CodeAnalysis ;
@@ -223,25 +221,10 @@ private sealed class AccessRegistrar
223221 {
224222 private delegate void ReportFileAccessFn ( FileAccessData fileAccessData ) ;
225223
226- private delegate FileAccessData CreateFileAccessFn (
227- ReportedFileOperation operation ,
228- RequestedAccess requestedAccess ,
229- uint processId ,
230- uint id ,
231- uint correlationId ,
232- uint error ,
233- DesiredAccess desiredAccess ,
234- FlagsAndAttributes flagsAndAttributes ,
235- string path ,
236- string processArgs ,
237- bool isAnAugmentedFileAccess ) ;
238-
239224 private readonly string _basePath ;
240225
241226 private readonly ReportFileAccessFn _reportFileAccess ;
242227
243- private readonly CreateFileAccessFn _createFileAccess ;
244-
245228 private static readonly uint ProcessId = ( uint )
246229#if NET472
247230 Process . GetCurrentProcess ( ) . Id ;
@@ -257,57 +240,6 @@ public AccessRegistrar(string basePath, EngineServices engineServices)
257240 // Use reflection to get the ReportFileAccess method since it's not exposed.
258241 // TODO: Once there is a proper API for this, use it.
259242 _reportFileAccess = ( ReportFileAccessFn ) Delegate . CreateDelegate ( typeof ( ReportFileAccessFn ) , engineServices , "ReportFileAccess" ) ;
260-
261- ConstructorInfo fileAccessDataCtor = typeof ( FileAccessData ) . GetConstructors ( ) [ 0 ] ;
262- ParameterInfo [ ] fileAccessDataCtorParams = fileAccessDataCtor . GetParameters ( ) ;
263- if ( fileAccessDataCtorParams . Length = = 9 )
264- {
265- // This is the one we compiled against so just use it.
266- _createFileAccess = (
267- ReportedFileOperation operation ,
268- RequestedAccess requestedAccess ,
269- uint processId ,
270- uint id ,
271- uint correlationId ,
272- uint error ,
273- DesiredAccess desiredAccess ,
274- FlagsAndAttributes flagsAndAttributes ,
275- string path ,
276- string processArgs ,
277- bool isAnAugmentedFileAccess )
278- => new FileAccessData ( operation , requestedAccess , processId , error , desiredAccess , flagsAndAttributes , path , processArgs , isAnAugmentedFileAccess ) ;
279- }
280- else if ( fileAccessDataCtorParams . Length = = 11 )
281- {
282- // Adjust to a breaking change made in MSBuild to the FileAccessData ctor. See: https://github.com/dotnet/msbuild/pull/9615
283- // Create a dynamic method which basically just invokes the ctor with all the params from the CreateFileAccessFn delegate.
284- DynamicMethod dynamicMethod = new (
285- name : string . Empty ,
286- returnType : typeof ( FileAccessData ) ,
287- parameterTypes : fileAccessDataCtorParams . Select ( param => param . ParameterType ) . ToArray ( ) ,
288- owner : typeof ( FileAccessData ) ) ;
289-
290- ILGenerator il = dynamicMethod . GetILGenerator ( ) ;
291- il . Emit ( OpCodes . Ldarg_0) ;
292- il . Emit ( OpCodes . Ldarg_1) ;
293- il . Emit ( OpCodes . Ldarg_2) ;
294- il . Emit ( OpCodes . Ldarg_3) ;
295- il . Emit ( OpCodes . Ldarg_S, 4 ) ;
296- il . Emit ( OpCodes . Ldarg_S, 5 ) ;
297- il . Emit ( OpCodes . Ldarg_S, 6 ) ;
298- il . Emit ( OpCodes . Ldarg_S, 7 ) ;
299- il . Emit ( OpCodes . Ldarg_S, 8 ) ;
300- il . Emit ( OpCodes . Ldarg_S, 9 ) ;
301- il . Emit ( OpCodes . Ldarg_S, 10 ) ;
302- il . Emit ( OpCodes . Newobj, fileAccessDataCtor ) ;
303- il . Emit ( OpCodes . Ret) ;
304-
305- _createFileAccess = ( CreateFileAccessFn ) dynamicMethod . CreateDelegate ( typeof ( CreateFileAccessFn ) ) ;
306- }
307- else
308- {
309- throw new MissingMethodException ( "Could not find supported constructor for FileAccessData" ) ;
310- }
311243 }
312244
313245 public void RegisterOutput ( string ? filePath ) => RegisterAccess ( filePath , RequestedAccess . Write , DesiredAccess . GENERIC_WRITE ) ;
@@ -338,7 +270,7 @@ private void RegisterAccess(string? filePath, RequestedAccess requestedAccess, D
338270 return ;
339271 }
340272
341- FileAccessData fileAccessData = _createFileAccess (
273+ FileAccessData fileAccessData = new (
342274 ReportedFileOperation . CreateFile ,
343275 requestedAccess ,
344276 ProcessId ,
0 commit comments