public WeaverHelper(string projectPath, bool createTemporaryAssemblies)
    {
        this.projectPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\", projectPath));

        GetAssemblyPath();


        string newAssembly;

        if (createTemporaryAssemblies)
        {
            newAssembly = assemblyPath.Replace(".dll", "TempFile.dll");
        }
        else
        {
            newAssembly = assemblyPath.Replace(".dll", "MemoryFile.dll");
        }
        var pdbFileName    = Path.ChangeExtension(assemblyPath, "pdb");
        var newPdbFileName = Path.ChangeExtension(newAssembly, "pdb");

        File.Copy(assemblyPath, newAssembly, true);
        File.Copy(pdbFileName, newPdbFileName, true);
        var myBuildEngine = new StubBuildEngine
        {
            ProjectFileOfTaskNode = this.projectPath
        };
        var referenceCopyLocalPaths = GetCopyLocal().ToList();
        var embedTask = new EmbedTask
        {
            TargetPath                = newAssembly,
            BuildEngine               = myBuildEngine,
            References                = GetReferences(),
            DeleteReferences          = false,
            ReferenceCopyLocalPaths   = referenceCopyLocalPaths,
            CreateTemporaryAssemblies = createTemporaryAssemblies
        };

        var execute = embedTask.Execute();

        if (!execute)
        {
            throw embedTask.Exception;
        }
#if (RELEASE)
        foreach (var referenceCopyLocalPath in referenceCopyLocalPaths)
        {
            File.Delete(referenceCopyLocalPath);
        }
#endif
        Assembly = Assembly.LoadFile(newAssembly);
    }
Example #2
0
    public WeaverHelper(string projectPath, bool createTemporaryAssemblies)
    {
        this.projectPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\", projectPath));

        GetAssemblyPath();

        string newAssembly;
        if (createTemporaryAssemblies)
        {
            newAssembly = assemblyPath.Replace(".dll", "TempFile.dll");
        }
        else
        {
            newAssembly = assemblyPath.Replace(".dll", "MemoryFile.dll");
        }
        var pdbFileName = Path.ChangeExtension(assemblyPath, "pdb");
        var newPdbFileName = Path.ChangeExtension(newAssembly, "pdb");
        File.Copy(assemblyPath, newAssembly, true);
        File.Copy(pdbFileName, newPdbFileName, true);
        var myBuildEngine = new StubBuildEngine
                                {
                                    ProjectFileOfTaskNode = this.projectPath
                                };
        var referenceCopyLocalPaths = GetCopyLocal().ToList();
        var embedTask = new EmbedTask
                            {
                                TargetPath = newAssembly,
                                BuildEngine = myBuildEngine,
                                References = GetReferences(),
                                DeleteReferences = false,
                                ReferenceCopyLocalPaths = referenceCopyLocalPaths,
                                CreateTemporaryAssemblies = createTemporaryAssemblies
                            };

        var execute = embedTask.Execute();
        if (!execute)
        {
            throw embedTask.Exception;
        }
        #if (RELEASE)
            foreach (var referenceCopyLocalPath in referenceCopyLocalPaths)
            {
                File.Delete(referenceCopyLocalPath);
            }
        #endif
        Assembly = Assembly.LoadFile(newAssembly);
    }