예제 #1
0
파일: SGen.cs 프로젝트: nikson/msbuild
        /// <summary>
        /// Returns a string with those switches and other information that can't go into a response file and
        /// must go directly onto the command line.
        /// Called after ValidateParameters and SkipTaskExecution
        /// </summary>
        override protected string GenerateCommandLineCommands()
        {
            CommandLineBuilderExtension commandLineBuilder = new CommandLineBuilderExtension();
            bool serializationAssemblyPathExists = false;
            try
            {
                if (SerializationAssembly == null)
                {
                    Debug.Assert(ShouldGenerateSerializer, "GenerateCommandLineCommands() should not be called if ShouldGenerateSerializer is true and SerializationAssembly is null.");

                    SerializationAssembly = new TaskItem[] { new TaskItem(SerializationAssemblyPath) };
                }

                // Add the assembly switch
                commandLineBuilder.AppendSwitchIfNotNull("/assembly:", AssemblyFullPath);

                commandLineBuilder.AppendWhenTrue("/proxytypes", Bag, "UseProxyTypes");

                //add the keep switch
                commandLineBuilder.AppendWhenTrue("/keep", Bag, "UseKeep");

                // Append the references, if any.
                if (References != null)
                {
                    foreach (string reference in References)
                    {
                        commandLineBuilder.AppendSwitchIfNotNull("/reference:", reference);
                    }
                }

                //Append the Types to the command line, if any.
                if (Types != null)
                {
                    foreach (string type in Types)
                    {
                        commandLineBuilder.AppendSwitchIfNotNull("/type:", type);
                    }
                }

                // The arguments to the "/compiler" switch are themselves switches to be passed to
                // the compiler when generating the serialization assembly.

                // Add the compiler command switches for strong naming on the serialization assembly          
                if (KeyFile != null)
                {
                    commandLineBuilder.AppendNestedSwitch("/compiler:", "/keyfile:", KeyFile);
                }
                else if (KeyContainer != null)
                {
                    commandLineBuilder.AppendNestedSwitch("/compiler:", "/keycontainer:", KeyContainer);
                }

                commandLineBuilder.AppendPlusOrMinusSwitch("/compiler:/delaysign", Bag, "DelaySign");

                // Add the Platform switch to the compiler.
                if (Platform != null)
                {
                    commandLineBuilder.AppendNestedSwitch("/compiler:", "/platform:", Platform);
                }

                serializationAssemblyPathExists = File.Exists(SerializationAssemblyPath);
            }
            catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
            {
                // Ignore the expected exceptions because they have already been logged
            }

            // Delete the assembly if it already exists.
            if (serializationAssemblyPathExists)
            {
                try
                {
                    File.Delete(SerializationAssemblyPath);
                }
                // Of all of the exceptions that can be thrown on a File.Delete, the only ones we need to
                // be immediately concerned with are the UnauthorizedAccessException and the IOException
                // (file is in use exception).  We need to make sure that the assembly is gone before we
                // try to produce a new one because it is possible that after some changes were made to the
                // base assembly, there will, in fact, not be a serialization assembly produced.  We cannot
                // leave the earlier produced assembly around to be propagated by later processes.
                catch (UnauthorizedAccessException e)
                {
                    Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath, e.Message);
                }
                catch (IOException e)
                {
                    Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath, e.Message);
                }
                // The DirectoryNotFoundException is safely ignorable since that means that there is no
                // existing serialization assembly.  This would be extremely unlikely anyway because we
                // found the serializer just a couple of milliseconds ago.
            }

            return commandLineBuilder.ToString();
        }
예제 #2
0
        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilderExtension extension = new CommandLineBuilderExtension();
            bool flag = false;

            try
            {
                if (this.SerializationAssembly == null)
                {
                    this.SerializationAssembly = new TaskItem[] { new TaskItem(this.SerializationAssemblyPath) };
                }
                extension.AppendSwitchIfNotNull("/assembly:", this.AssemblyFullPath);
                extension.AppendWhenTrue("/proxytypes", base.Bag, "UseProxyTypes");
                if (this.References != null)
                {
                    foreach (string str in this.References)
                    {
                        extension.AppendSwitchIfNotNull("/reference:", str);
                    }
                }
                if (this.Types != null)
                {
                    foreach (string str2 in this.Types)
                    {
                        extension.AppendSwitchIfNotNull("/type:", str2);
                    }
                }
                if (this.KeyFile != null)
                {
                    extension.AppendNestedSwitch("/compiler:", "/keyfile:", this.KeyFile);
                }
                else if (this.KeyContainer != null)
                {
                    extension.AppendNestedSwitch("/compiler:", "/keycontainer:", this.KeyContainer);
                }
                extension.AppendPlusOrMinusSwitch("/compiler:/delaysign", base.Bag, "DelaySign");
                if (this.Platform != null)
                {
                    extension.AppendNestedSwitch("/compiler:", "/platform:", this.Platform);
                }
                flag = File.Exists(this.SerializationAssemblyPath);
            }
            catch (Exception exception)
            {
                if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception))
                {
                    throw;
                }
            }
            if (flag)
            {
                try
                {
                    File.Delete(this.SerializationAssemblyPath);
                }
                catch (UnauthorizedAccessException exception2)
                {
                    base.Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", new object[] { this.SerializationAssemblyPath, exception2.Message });
                }
                catch (IOException exception3)
                {
                    base.Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", new object[] { this.SerializationAssemblyPath, exception3.Message });
                }
            }
            return(extension.ToString());
        }
예제 #3
0
        /// <summary>
        /// Returns a string with those switches and other information that can't go into a response file and
        /// must go directly onto the command line.
        /// Called after ValidateParameters and SkipTaskExecution
        /// </summary>
        override protected string GenerateCommandLineCommands()
        {
            CommandLineBuilderExtension commandLineBuilder = new CommandLineBuilderExtension();
            bool serializationAssemblyPathExists           = false;

            try
            {
                if (SerializationAssembly == null)
                {
                    Debug.Assert(ShouldGenerateSerializer, "GenerateCommandLineCommands() should not be called if ShouldGenerateSerializer is true and SerializationAssembly is null.");

                    SerializationAssembly = new TaskItem[] { new TaskItem(SerializationAssemblyPath) };
                }

                // Add the assembly switch
                commandLineBuilder.AppendSwitchIfNotNull("/assembly:", AssemblyFullPath);

                commandLineBuilder.AppendWhenTrue("/proxytypes", Bag, "UseProxyTypes");

                //add the keep switch
                commandLineBuilder.AppendWhenTrue("/keep", Bag, "UseKeep");

                // Append the references, if any.
                if (References != null)
                {
                    foreach (string reference in References)
                    {
                        commandLineBuilder.AppendSwitchIfNotNull("/reference:", reference);
                    }
                }

                //Append the Types to the command line, if any.
                if (Types != null)
                {
                    foreach (string type in Types)
                    {
                        commandLineBuilder.AppendSwitchIfNotNull("/type:", type);
                    }
                }

                // The arguments to the "/compiler" switch are themselves switches to be passed to
                // the compiler when generating the serialization assembly.

                // Add the compiler command switches for strong naming on the serialization assembly
                if (KeyFile != null)
                {
                    commandLineBuilder.AppendNestedSwitch("/compiler:", "/keyfile:", KeyFile);
                }
                else if (KeyContainer != null)
                {
                    commandLineBuilder.AppendNestedSwitch("/compiler:", "/keycontainer:", KeyContainer);
                }

                commandLineBuilder.AppendPlusOrMinusSwitch("/compiler:/delaysign", Bag, "DelaySign");

                // Add the Platform switch to the compiler.
                if (Platform != null)
                {
                    commandLineBuilder.AppendNestedSwitch("/compiler:", "/platform:", Platform);
                }

                serializationAssemblyPathExists = File.Exists(SerializationAssemblyPath);
            }
            catch (Exception e) when(ExceptionHandling.IsIoRelatedException(e))
            {
                // Ignore the expected exceptions because they have already been logged
            }

            // Delete the assembly if it already exists.
            if (serializationAssemblyPathExists)
            {
                try
                {
                    File.Delete(SerializationAssemblyPath);
                }
                // Of all of the exceptions that can be thrown on a File.Delete, the only ones we need to
                // be immediately concerned with are the UnauthorizedAccessException and the IOException
                // (file is in use exception).  We need to make sure that the assembly is gone before we
                // try to produce a new one because it is possible that after some changes were made to the
                // base assembly, there will, in fact, not be a serialization assembly produced.  We cannot
                // leave the earlier produced assembly around to be propagated by later processes.
                catch (UnauthorizedAccessException e)
                {
                    Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath, e.Message);
                }
                catch (IOException e)
                {
                    Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath, e.Message);
                }
                // The DirectoryNotFoundException is safely ignorable since that means that there is no
                // existing serialization assembly.  This would be extremely unlikely anyway because we
                // found the serializer just a couple of milliseconds ago.
            }

            return(commandLineBuilder.ToString());
        }
 protected override string GenerateCommandLineCommands()
 {
     CommandLineBuilderExtension extension = new CommandLineBuilderExtension();
     bool flag = false;
     try
     {
         if (this.SerializationAssembly == null)
         {
             this.SerializationAssembly = new TaskItem[] { new TaskItem(this.SerializationAssemblyPath) };
         }
         extension.AppendSwitchIfNotNull("/assembly:", this.AssemblyFullPath);
         extension.AppendWhenTrue("/proxytypes", base.Bag, "UseProxyTypes");
         if (this.References != null)
         {
             foreach (string str in this.References)
             {
                 extension.AppendSwitchIfNotNull("/reference:", str);
             }
         }
         if (this.Types != null)
         {
             foreach (string str2 in this.Types)
             {
                 extension.AppendSwitchIfNotNull("/type:", str2);
             }
         }
         if (this.KeyFile != null)
         {
             extension.AppendNestedSwitch("/compiler:", "/keyfile:", this.KeyFile);
         }
         else if (this.KeyContainer != null)
         {
             extension.AppendNestedSwitch("/compiler:", "/keycontainer:", this.KeyContainer);
         }
         extension.AppendPlusOrMinusSwitch("/compiler:/delaysign", base.Bag, "DelaySign");
         if (this.Platform != null)
         {
             extension.AppendNestedSwitch("/compiler:", "/platform:", this.Platform);
         }
         flag = File.Exists(this.SerializationAssemblyPath);
     }
     catch (Exception exception)
     {
         if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception))
         {
             throw;
         }
     }
     if (flag)
     {
         try
         {
             File.Delete(this.SerializationAssemblyPath);
         }
         catch (UnauthorizedAccessException exception2)
         {
             base.Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", new object[] { this.SerializationAssemblyPath, exception2.Message });
         }
         catch (IOException exception3)
         {
             base.Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", new object[] { this.SerializationAssemblyPath, exception3.Message });
         }
     }
     return extension.ToString();
 }