Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSCli.exe exits unsuccessfully because blocked CSCore.dll #286

Closed
Erhie opened this issue Oct 19, 2017 · 0 comments
Closed

CSCli.exe exits unsuccessfully because blocked CSCore.dll #286

Erhie opened this issue Oct 19, 2017 · 0 comments
Labels

Comments

@Erhie
Copy link

Erhie commented Oct 19, 2017

With Windows 10 and Mono.Cecil v0.9.6.4 there are problems to build CSCore, because the
Post-build event commands execute CSCli exe with failure, because the file CSCore.dll is blocked.
My patch of this section of Tools\CSCli\Program.cs :


            /*
             * Load and process assembly
             */
            if (!File.Exists(filename))
            {
                MessageIntegration.WriteError(String.Format("Could not find file \"{0}\".", filename));
                Environment.Exit(-4);
            }
            string origfilename = filename + "_orig"; //use this filename for reader of Mono.Cecil
            File.Delete(origfilename); //delete previous version, if existing 
            try
            {
                File.Move(filename, origfilename); //file for reader
            }
            catch (Exception ex)
            {
                MessageIntegration.WriteError("Rename file to _orig failed: " + ex.ToString());
                Environment.Exit(-3);
            }
            
            WriterParameters wp = new WriterParameters();
            ReaderParameters rp = new ReaderParameters();

            var strongNameKey = Path.ChangeExtension(filename, "snk");
            if (File.Exists(strongNameKey))
            {
                MessageIntegration.Info("Signing with Key : " + strongNameKey);
                wp.StrongNameKeyPair = new StrongNameKeyPair(File.OpenRead(strongNameKey));
            }

            //check whether the pdbfile has been passed through application parameters
            if (pdbfile == null)
            {
                //if not use the default pdbfilepath by changing the extension of the assembly to .pdb
                pdbfile = Path.ChangeExtension(filename, "pdb");
            }

            //check whether the original pdb-file exists
            bool generatePdb = File.Exists(pdbfile);

            //if the original pdb-file exists -> prepare for rewriting the symbols file
            wp.WriteSymbols = generatePdb;
            rp.ReadSymbols = generatePdb;

            if (rp.ReadSymbols)
            {
                rp.SymbolReaderProvider = new PdbReaderProvider();
            }

            MessageIntegration.Info("Generating pdb: " + generatePdb.ToString());

            //open assembly
            var assembly = AssemblyDefinition.ReadAssembly(origfilename, rp); //read
            //add the directory assembly directory as search directory to resolve referenced assemblies
            ((BaseAssemblyResolver)assembly.MainModule.AssemblyResolver).AddSearchDirectory(Path.GetDirectoryName(origfilename));

            //path the assembly
            AssemblyPatcher patcher = new AssemblyPatcher(assembly, calliAttributeName, removeTypeAttributeName);
            if (patcher.PatchAssembly())
            {
                try
                {
                    assembly.Write(filename, wp);
                }
                catch (Exception ex)
                {
                    MessageIntegration.WriteError("Creating patched assembly failed: " + ex.ToString());
                    Environment.Exit(-2);
                }

                MessageIntegration.Info(String.Format("CSCli patched assembly \"{0}\" successfully.", Path.GetFileName(filename)));
                Environment.Exit(0);
            }
            else
            {
                MessageIntegration.WriteError(String.Format("\"{0}\" could not be patched.", filename));
                Environment.Exit(-1);
            }

@filoe filoe added the bug label Oct 21, 2017
@filoe filoe closed this as completed in 96df808 Oct 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants