c# - Is it possible to generate Satellite Assemblies from within code? -
i'm elaborate solution simplifying translator tool. therefore try automatically compile satellite assembly within code.
so want achive replace manual run of following command:
al.exe /culture:de /out:de\testresource.resources.dll /embed:testresource.de.resources
so far i've tested generating .dll file, worked. embedding/linking ressource shown below doesn't has effect, expanding dll's size. it's there not usable if resulting dll satellite assembly.
static void main(string[] args) { csharpcodeprovider codeprovider = new csharpcodeprovider(); compilerparameters parameters = new compilerparameters(); parameters.generateexecutable = false; parameters.outputassembly = "./output/satellite_test.dll"; parameters.embeddedresources.add(@"./testresource.en.resources"); parameters.linkedresources.add(@"./testresource.de.resources"); compilerresults results = codeprovider.compileassemblyfromsource(parameters, ""); }
is there way generate dll programmatically contains localized resources 1 language, it's usable satellite assembly?
finally i've managed generate satellite assemblies code.
following code generates appropriate resourcefile:
// resourcefilename has match // exact namespacepath of original resourcename. var resourcefilename = @"translationtest.resources.testresource.de.resources"; // file has .resource file. (resourcewriter instead of resxresourcewriter) // .resx not working , has converted .resource file. using (var resourcewriter = new resourcewriter(resourcefilename)) { resourcewriter.addresource("testtext", "language german!!"); }
using resourcefile there compileroptions necessary:
compilerparameters parameters = new compilerparameters(); // newly created assembly has dll. parameters.generateexecutable = false; // filename has original resourcename. renaming afterwards not work. parameters.outputassembly = "./de/translationtest.resources.dll"; // resourcefile has embedded in new assembly. parameters.embeddedresources.add(resourcefilename);
finally compiling assembly there required code has compiled into:
// culture information has part of newly created assembly. var assemblyattributesascode = @" using system.reflection; [assembly: assemblyculture(""de"")]"; csharpcodeprovider codeprovider = new csharpcodeprovider(); compilerresults results = codeprovider.compileassemblyfromsource( parameters, assemblyattributesascode );
Comments
Post a Comment