本文整理汇总了C#中ModuleDefinition.Write方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleDefinition.Write方法的具体用法?C# ModuleDefinition.Write怎么用?C# ModuleDefinition.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleDefinition
的用法示例。
在下文中一共展示了ModuleDefinition.Write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InMemoryTests
public InMemoryTests()
{
beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll");
var directoryName = Path.GetDirectoryName(@"..\..\..\Debug\");
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
directoryName = directoryName.Replace("Debug", "Release");
#endif
afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "InMemory.dll");
File.Copy(beforeAssemblyPath, afterAssemblyPath, true);
File.Copy(beforeAssemblyPath.Replace(".dll", ".pdb"), afterAssemblyPath.Replace(".dll", ".pdb"), true);
var readerParams = new ReaderParameters() { ReadSymbols = true };
moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath, readerParams);
var references = new List<string>
{
beforeAssemblyPath.Replace("AssemblyToProcess", "AssemblyToReference"),
beforeAssemblyPath.Replace("AssemblyToProcess", "AssemblyToReferencePreEmbed"),
Path.ChangeExtension(beforeAssemblyPath.Replace("AssemblyToProcess", "ExeToReference"), "exe"),
Path.Combine(directoryName, "AssemblyToReferenceMixed.dll"),
};
var assemblyToReferenceDirectory = Path.GetDirectoryName(beforeAssemblyPath.Replace("AssemblyToProcess", "AssemblyToReference"));
var assemblyToReferenceResources = Directory.GetFiles(assemblyToReferenceDirectory, "*.resources.dll", SearchOption.AllDirectories);
references.AddRange(assemblyToReferenceResources);
using (var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = new MockAssemblyResolver(),
Config = XElement.Parse("<Costura Unmanaged32Assemblies='AssemblyToReferenceMixed' PreloadOrder='AssemblyToReferenceNative' />"),
ReferenceCopyLocalPaths = references,
AssemblyFilePath = beforeAssemblyPath
})
{
weavingTask.Execute();
var writerParams = new WriterParameters() { WriteSymbols = true };
moduleDefinition.Write(afterAssemblyPath, writerParams);
}
isolatedPath = Path.Combine(Path.GetTempPath(), "CosturaIsolatedMemory.dll");
File.Copy(afterAssemblyPath, isolatedPath, true);
File.Copy(afterAssemblyPath.Replace(".dll", ".pdb"), isolatedPath.Replace(".dll", ".pdb"), true);
assembly = Assembly.LoadFile(isolatedPath);
}
示例2: PureDotNetAssemblyTests
public PureDotNetAssemblyTests()
{
beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcessWithoutUnmanaged\bin\Debug\AssemblyToProcessWithoutUnmanaged.dll");
var directoryName = Path.GetDirectoryName(@"..\..\..\Debug\");
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
directoryName = directoryName.Replace("Debug", "Release");
#endif
afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "InMemory.dll");
File.Copy(beforeAssemblyPath, afterAssemblyPath, true);
File.Copy(beforeAssemblyPath.Replace(".dll", ".pdb"), afterAssemblyPath.Replace(".dll", ".pdb"), true);
var readerParams = new ReaderParameters() { ReadSymbols = true };
moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath, readerParams);
var references = new List<string>
{
beforeAssemblyPath.Replace("AssemblyToProcessWithoutUnmanaged", "AssemblyToReference"),
};
var assemblyToReferenceDirectory = Path.GetDirectoryName(beforeAssemblyPath.Replace("AssemblyToProcessWithoutUnmanaged", "AssemblyToReference"));
var assemblyToReferenceResources = Directory.GetFiles(assemblyToReferenceDirectory, "*.resources.dll", SearchOption.AllDirectories);
references.AddRange(assemblyToReferenceResources);
// This should use ILTemplate instead of ILTemplateWithUnmanagedHandler.
using (var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = new MockAssemblyResolver(),
Config = XElement.Parse("<Costura />"),
ReferenceCopyLocalPaths = references,
AssemblyFilePath = beforeAssemblyPath
})
{
weavingTask.Execute();
var writerParams = new WriterParameters() { WriteSymbols = true };
moduleDefinition.Write(afterAssemblyPath, writerParams);
}
isolatedPath = Path.Combine(Path.GetTempPath(), "CosturaPureDotNetIsolatedMemory.dll");
File.Copy(afterAssemblyPath, isolatedPath, true);
File.Copy(afterAssemblyPath.Replace(".dll", ".pdb"), isolatedPath.Replace(".dll", ".pdb"), true);
assembly = Assembly.LoadFile(isolatedPath);
}
示例3: CultureResourceTest
public CultureResourceTest()
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll");
var directoryName = Path.GetDirectoryName(@"..\..\..\Debug\");
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
directoryName = directoryName.Replace("Debug", "Release");
#endif
afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "Culture.dll");
File.Copy(beforeAssemblyPath, afterAssemblyPath, true);
moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath);
var references = new List<string>
{
beforeAssemblyPath.Replace("AssemblyToProcess", "AssemblyToReference"),
beforeAssemblyPath.Replace("AssemblyToProcess", "AssemblyToReferencePreEmbed"),
Path.ChangeExtension(beforeAssemblyPath.Replace("AssemblyToProcess", "ExeToReference"), "exe"),
Path.Combine(directoryName, "AssemblyToReferenceMixed.dll"),
};
var assemblyToReferenceDirectory = Path.GetDirectoryName(beforeAssemblyPath.Replace("AssemblyToProcess", "AssemblyToReference"));
var assemblyToReferenceResources = Directory.GetFiles(assemblyToReferenceDirectory, "*.resources.dll", SearchOption.AllDirectories);
references.AddRange(assemblyToReferenceResources);
using (var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = new MockAssemblyResolver(),
Config = XElement.Parse("<Costura Unmanaged32Assemblies='AssemblyToReferenceMixed' />"),
ReferenceCopyLocalPaths = references,
AssemblyFilePath = beforeAssemblyPath
})
{
weavingTask.Execute();
moduleDefinition.Write(afterAssemblyPath);
}
isolatedPath = Path.Combine(Path.GetTempPath(), "CosturaCulture.dll");
File.Copy(afterAssemblyPath, isolatedPath, true);
assembly = Assembly.LoadFile(isolatedPath);
}