Search code examples
c#compilation.net-assemblycsc

Exclude certain files from compiling in directory


I am trying to create multi file assembly by creating .netmodules for respective Visual Studio projects. These .netmodules are being created successfully. Command used to produce the modules:

csc.exe "/out:$(ProjectDir)$(ProjectName).netmodule" "/t:module" "/recurse:$(ProjectDir)*.cs"

The problem with the above command is the switch :/recurse:$(ProjectDir)*.cs, which compiles all files in the project including AssemblyInfo.cs file. This file is compiled for each project.

At the end when I am trying to build a multi file assembly using following command:

csc.exe /t:library /out:MultiFile.dll /addmodule:Foo.netmodule /addmodule:Boo.netmodule

I get the error error CS7061: Duplicate 'GuidAttribute' attribute in 'Foo.netmodule'

Please state any ways to create multi file assembly.

As of me, I can think of two ways, deleting the AssemblyInfo.cs files from project or find a way to exclude the specific files from compiling in the /recurse switch (don't know how to exclude the file).


Solution

  • Although it would be nice to pass some parameter to CSC.exe to exclude some files from /recurse switch. I did not find it anywhere. Solution I opted for:

    1. Copy all source files for each Visual Studio project to different folder, excluding the AssemblyInfo.cs file.

    2. Compile all the files from that folder to produce .netmodule.