0

In my current Job we have a big C# library and it is made up of a lot of files etc. I'm quite new to visual studio and C# in general, is there a way for me to see a big list of the c# files which are called in the compilation of my code? I would like to see from start to finish the .cs files which are called and used and when. This would give me a good idea of which files are implemented first and which ones are not used at all. It's quite a big library and the debugging will only get me so far, since it jumps around the library a lot and it can be quite confusing...

Any help will be greatly appreciated!

  • Are you looking for the Solution Explorer in Visual Studio? – Klaus Gütter Aug 17 '20 at 11:44
  • no, I've used that but it's more of a searching tool, rather than like a list of the used when the code is compiled. – loprocto Aug 17 '20 at 12:24
  • Then it's not at all clear to me what you really want. If it's not the list of cs files: do you want some information about runtime dependencies? Or is it about editing history? – Klaus Gütter Aug 17 '20 at 12:44
  • I want a list of files used when I compile code. The library has a lot of .cs files which aren't used, and I want a list of the ones which are used and what order. – loprocto Aug 17 '20 at 12:52
  • It seems to be the reverse of https://stackoverflow.com/questions/30974433/get-list-of-zero-reference-codes-in-visual-studio – Martheen Aug 17 '20 at 12:57
  • *All* .cs files showing up in the solution explorer will be compiled into the resulting assembly. For a libary it's hard to tell what's actually used and what not - this is mostly determined by the app(s) using it. And what do you mean with "what order"? – Klaus Gütter Aug 17 '20 at 13:23
  • @Klaus, that is mostly true... though you could have .cs files not marked as compile in which case they would not be included in the output. – Matthew Whited Aug 18 '20 at 05:04

2 Answers2

0

When you compile a project that references other projects, Visual Studio by default saves the files in bin/Debug when you are on a Debug mode. So you can see which are the libraries that contain other files marked explicitly as a reference from your project. Now, having a library there doesn't mean that your code on runtime uses it. This gives you a starting point to discover at least which .cs files are going to be used when you run that project because all of them are contained on the binaries that are copied on that folder. When you run your code the principal thread loads all the referenced assemblies to execute its logic. Referenced assemblies are those that have an explicit reference on the code of the project you are running. Let's say that you load from a web project assemblies that you are going to use via reflection because you discover some plugins that you created on a plugin library. Even if you have a reference on your web project to those libraries it doesn't mean that they are going to be loaded on runtime using this code.

var assemblies = Assembly.GetEntryAssembly().GetReferencedAssemblies().Select(Assembly.Load);

If in your main project you don't use explicitly a reference of any class from your plugins libraries, those plugins libraries are not going to be part of the referenced assemblies. My point here is that your original set of assemblies from your bin/Debug are now reduced to the assemblies that your code really uses at runtime. With that, you can inspect those assemblies to see which are the classes you are using. Hope this helps

Zinov
  • 3,817
  • 5
  • 36
  • 70
  • Thank you so much I will try and locate the bin/Debug files thank you – loprocto Aug 17 '20 at 12:26
  • I have located the bin/Debug folder, If I sort them by date modified am I right in saying that the most recent file is the one that is executed first, then the last file is the one that is executed last? – loprocto Aug 17 '20 at 12:37
  • no, you can't say that those files are updated if they have changes, if not they will remain with the same date unless you clean the folders and visual studio will recreate them for you – Zinov Aug 17 '20 at 12:56
0

You can use my Runtime Flow tool, especially the Summary window, to see executed classes and methods of a program run.

Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66