The path to the .dll files was taken from here:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\

 List<string> DLL = new List<string>(); //тут уже лежит список путей к .dll using (var provider = new CSharpCodeProvider()) { // DLL.ToArray() добавляю ссылки var Params = new CompilerParameters() { //parametrs build }; provider.CompileAssemblyFromSource(Params, SourceCode) // compile } 

But at compile time I get an error:

error CS1703: Multiple assemblies with the equivalent identity have been imported: 'C: \ Windows \ Microsoft .NET \ Framework \ v4.0.30319 \ mscorlib.dll' and 'C: \ Program Files (x86) \ Reference \ Assemblies \ Microsoft \ Framework .NETFramework \ v3.5 \ Profile \ Client \ mscorlib.dll '.

Remove one of the duplicate references.

How to fix?


[ Additional Information ]

The project itself is compiled under .Net4.5

(especially for Roslyn , he does not install his library for other versions of NetFramework )

If you take this code:

 List<string> DLL = new List<string>() // просто файлы { "mscorlib.dll", "System.Data.dll" } using (var provider = new CSharpCodeProvider()) { var Params = new CompilerParameters(DLL.ToArray()) { //parametrs build }; provider.CompileAssemblyFromSource(Params, SourceCode) // compile } 

It all works, but it adds links from List<string> from the project itself (under which it was compiled) PS: Not from folders!

And I need to add from the folder I need, but if I do this (see 1st post), I get an error saying that you cannot add .dll libraries from different folders. How do I get the libraries I need and add them to the assembly I do not know how.


[ What did you do? ]

I tried to remove from the file that compiles links ( usings ).

I tried to remove the packages.config file

But all to no avail.

  • Obviously, taking files is not from all subfolders, but only from one - with the required version of the framework. Just open this folder in the explorer and see what's in it - Andrey NOP
  • @AndreyNOP, I collect only from the required version of the framework, I go through the folders (in the required version) looking for the files I need and add to the List<string> DLL . If I collect files from the v4.0 framework, then everything works fine. (The project itself is compiled in Net v4.5 ). - Luser
  • Yeah, I see you have C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll still picked up - Andrew NOP
  • @AndreyNOP, Roslyn somehow automatically generates these files under 4.0 I don’t know how to get rid of it. I basically need to somehow make it so that it collects links only from the necessary folder (using the example from v3.5 ) and from the project build itself (under which it is compiled) - Luser
  • one
    It looks as if the CoreAssemblyFileName property is empty ... - Pavel Mayorov

1 answer 1

By default, the compiler adds links to system assemblies, which are specified in the csc.rsp file in its directory. Add the nostdlib or noconfig compiler option if you don't need it.

In fact, it does not work. The behavior of Roslyn differs from the traditional C # compiler in that adding the /nostdlib option has no effect, a link to mscorlib 4.0 will be added anyway. The only way to not add a link to it is to set the CoreAssemblyFileName property to the path to another version of mscorlib and not to add a link to any assembly dependent on the "unnecessary" version.

  • The /nostdlib added automatically. Here /noconfig more interesting ... - Pavel Mayorov
  • @PavelMayorov I did not notice that the author added the installation of the property CoreAssemblyFileName. Without it, nostdlib was really needed. And in the current edition, he has a code for a campaign in general (at least, he does not issue errors to hello world). - MSDN.WhiteKnight
  • /nostdlib doesn't help without it either. Just because mscorlib is automatically added to the list of dependencies. - Pavel Mayorov
  • @ Dmitriy grr! To specify CoreAssemblyFileName, of course ... Stop asking me the same question. If I find out another answer to it - I will say this without your reminder. - Pavel Mayorov
  • one
    @ Dmitry I do not know. Ask a new question with the code and information about the exception, then we will try to figure it out. - MSDN.WhiteKnight