Good day!
There is a class:
using Microsoft.CodeAnalysis.CSharp.Scripting; using Microsoft.CodeAnalysis.Scripting; using System; using System.Reflection; namespace namespace1 { public class AClass { public void Run(string Code) { // Π€ΠΎΡΠΌΠΈΡΡΠ΅ΠΌ Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠΈ Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); ScriptOptions options = ScriptOptions.Default.AddReferences(assemblies); // ΠΠ°ΠΏΡΡΠΊΠ°Π΅ΠΌ ΡΠΊΡΠΈΠΏΡ var result = CSharpScript.RunAsync(Code, options); } } } It's simple: I get the builds of the current domain -> I copy them to the script settings -> I execute the script. The code I'm trying to pass to the Run procedure:
string code = @"using Excel = NetOffice.ExcelApi; " + @"Excel.Application ExcelApp = new Excel.Application(); "; As you noticed, in the transmitted code I use using. Which should refer to acc. dll (NetOffice.ExcelApi). In the project, this link is present: Properties
To the point: when I get AppDomain.CurrentDomain.GetAssemblies (), then there is no NetOffice assembly, respectively. As I understand it, this is due to the fact that the compiler is smart and does not load those assemblies that are not explicitly used in the code. Everything is logical (this was confirmed when I added a line to the code of the Run method:
NetOffice.ExcelApi.Application SomeVar = new NetOffice.ExcelApi.Application(); After, I decided that I would forcibly load the dll into the domain. But I found out that when building a project, this dll does not fall into the assembly files, although the "Copy locally" property stands on them.
In this regard, several
1) Is it possible to force the collector to copy unused unused references (dll) to the release folder?
2) Is it possible to get a list of all Assemblies (maybe just a list of names) in the code, including those that are not used explicitly? (non-ASP.NET application)
PS In C # the perfect newbie. 100% somewhere while I misunderstand some things. I ask to understand and forgive :) I would be grateful if you would advise good sources for pumping a skill in C #.
