c# - Mimicking assembly resolution of the msbuild process -


I am writing a verification tool that checks the version of files referenced in a project. I want to use the same resolution process which uses MSBuild.

For example, assembly.Load (..) requires a fully-qualified assembly name. However, in the project file, we can have just something like "System.Xml". MSBuild will probably use the version of the project's target framework and some other heuristics to decide the version to load the system.

How would you go about copying msbuild assembly resolution process (or using direct)?

In other words, run-time, I want to string "System.Xml" with other information received in .cproj file and he looks for the file that will msbuild.

Today I had this problem, and I have received this old blog post how to:

I tried it out, works great! I modified the code to find the 4.5.1 version when it is possible assemblies, now I have:

  #if Intraktiiv # R "Maikrosoftkbildkinjin" # R " Microsoft. Build .Framework "#R" Microsoft.Build.Tasks.v4.0 "#R" Microsoft.Build.Utilities.v4.0 "open system open System.Reflection open Microsoft.Build.Tasks #endif open Microsoft.Build .Utilities open Microsoft.Build.Framework open Microsoft.bild.bild engine /// reference proposal results all paths are fully qualified Type ResolutionResults = {refe RencePaths: string array referenceDependencyPaths: string array relatedPaths: string array referenceSatellitePaths: string array referenceScatterPaths: string array referenceCopyLocalPaths: string array suggestedBindingRedirects: string array} go resolution (reference: string array, outputDirectory: string) = know x = {member be.BuildProjectFile new IBuildEngine with (projectFileName, targetNames, globalProperties, targetOutputs) = true member BekLogCustomEvent (e) = () member BekLogErrorEvent (e) = () member BekLogMessageEvent (e) = () KLogWarningEvent be a member ( E) = () received () = 1 member get with be.Conti nueOnError (with member be.ColumnNumberOfTaskNode) = get () = true member with get 1 member be.ProjectFileOfTaskNode () = ""} be.LineNumberOfTaskNode RR = new Rijholyuesdamptr R eference () rar.BuildEngine & lt; - x rar.IgnoreVersionForFrameworkReferences & lt; - True rar.TargetFrameworkVersion & lt; - "v4.5.1" rar.TargetedRuntimeVersion & lt; - "v4.5.1" rar.TargetFrameworkDirectories & lt; - [||] / / [| @ "C: \ Program Files \ Reference Assemblies \ Microsoft \ Framework \ v3.5 \"] | Rar.Assemblies & lt; - for reference in r - & gt; New Microsoft.Bield.Taget (R): & gt; ITaskItem |] rar.AutoUnify & lt; - true rar.SearchPaths & lt; - [| "{CandidateAssemblyFiles}" "{HintPathFromItem}" "{} TargetFrameworkDirectory" //: "{AssemblyFolders}" {Registry Microsoft \ .NETFramework, v3.5, AssemblyFoldersEx \ Software} "" "{GAC}" "{RawFileName}" Output directory |] rar.AllowedAssemblyExtensions & lt; - [| ".exe"; ".dll" |] rar.TargetProcessorArchitecture & lt; - "x86" if not (rar.Execute ()) may fail "could not be resolved" {referencePaths = [| P for r Modified files - & gt; P.ItemSpec |] References dependency path = [| For P for R. Copy Independent Dependency - & gt; P.ItemSpec |] Related Paths = [| For in r Related files - & gt; P.ItemSpec |] with reference light path = [| P for r Satellite Files - & gt; P.ItemSpec |] Reference ScatterPaths = [| For R. Seaterfile - & gt; P.ItemSpec |] ReferenceCopy Locale = [| For rar.PopyLocalFiles P - & gt; P.ItemSpec |] SuggestionBank Redirex = [| For P in P Recommended redirects - & gt; P.ItemSpec |]} [& lt; EntryPoint & gt;] Let's get the main argv = try let s = resolve (["System" "System.Data" "System .core, version = 4.0.0.0" "Microsoft SQL Server." | "]," ") Printfn "% A" s.referencePaths Finally Deprecated (System.Console.ReadKey ()) 0  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -