コード例 #1
0
        public CreateBundlesWithRawFilesTests()
        {
            root = new TempDirectory();

            CreateDirectory("source");
            CreateDirectory("source\\bin");
            CreateDirectory("output");

            WriteFile("source\\test.css", @"p { background: url(test.png); } .other { background: url(notfound.png); }");
            WriteFile("source\\test.png", "image");

            var configurationDll = CompileConfigurationDll();

            File.Move(configurationDll, PathUtilities.Combine(root, "source", "bin", "test.dll"));
            File.Copy("Cassette.dll", PathUtilities.Combine(root, "source", "bin", "Cassette.dll"));
            File.Copy("Cassette.pdb", PathUtilities.Combine(root, "source", "bin", "Cassette.pdb"));
            File.Copy("AjaxMin.dll", PathUtilities.Combine(root, "source", "bin", "AjaxMin.dll"));
            #if NET35
            File.Copy("Iesi.Collections.dll", PathUtilities.Combine(root, "source", "bin", "Iesi.Collections.dll"));
            #endif

            var command = new CreateBundlesCommand(
                PathUtilities.Combine(root, "source"),
                PathUtilities.Combine(root, "source", "bin"),
                PathUtilities.Combine(root, "output"),
                true
            );

            CreateBundlesCommand.ExecuteInSeparateAppDomain(command);
        }
コード例 #2
0
        public CreateBundlesWithRawFilesTests()
        {
            root = new TempDirectory();

            CreateDirectory("source");
            CreateDirectory("source\\bin");
            CreateDirectory("output");

            WriteFile("source\\test.css", @"p { background: url(test.png); } .other { background: url(notfound.png); }");
            WriteFile("source\\test.png", "image");

            var configurationDll = CompileConfigurationDll();

            File.Move(configurationDll, Path.Combine(root, "source", "bin", "test.dll"));
            File.Copy("Cassette.dll", Path.Combine(root, "source", "bin", "Cassette.dll"));
            File.Copy("Cassette.pdb", Path.Combine(root, "source", "bin", "Cassette.pdb"));
            File.Copy("AjaxMin.dll", Path.Combine(root, "source", "bin", "AjaxMin.dll"));

            var command = new CreateBundlesCommand(
                Path.Combine(root, "source"),
                Path.Combine(root, "source", "bin"),
                Path.Combine(root, "output"),
                true
                );

            CreateBundlesCommand.ExecuteInSeparateAppDomain(command);
        }
コード例 #3
0
 static void AssignConfigurationFile(CreateBundlesCommand command, AppDomainSetup setup)
 {
     var configFilename = Path.Combine(command.source, "web.config");
     if (File.Exists(configFilename))
     {
         setup.ConfigurationFile = configFilename;
     }
 }
コード例 #4
0
        static void AssignConfigurationFile(CreateBundlesCommand command, AppDomainSetup setup)
        {
            var configFilename = Path.Combine(command.source, "web.config");

            if (File.Exists(configFilename))
            {
                setup.ConfigurationFile = configFilename;
            }
        }
コード例 #5
0
 static AppDomainSetup CreateAppDomainSetup(CreateBundlesCommand command)
 {
     var setup = new AppDomainSetup
     {
         ApplicationBase = command.bin,
         ShadowCopyFiles = "true"
     };
     AssignConfigurationFile(command, setup);
     return setup;
 }
コード例 #6
0
        static AppDomainSetup CreateAppDomainSetup(CreateBundlesCommand command)
        {
            var setup = new AppDomainSetup
            {
                ApplicationBase = command.bin,
                ShadowCopyFiles = "true"
            };

            AssignConfigurationFile(command, setup);
            return(setup);
        }
コード例 #7
0
 public static void ExecuteInSeparateAppDomain(CreateBundlesCommand command)
 {
     var setup = CreateAppDomainSetup(command);
     var appDomain = AppDomain.CreateDomain("Cassette-MSBuild-AppDomain", null, setup);
     try
     {
         var commandInAppDomain = CreateCommandInAppDomain(command, appDomain);
         commandInAppDomain.Execute();
     }
     finally
     {
         AppDomain.Unload(appDomain);
     }
 }
コード例 #8
0
        public static void ExecuteInSeparateAppDomain(CreateBundlesCommand command)
        {
            var setup     = CreateAppDomainSetup(command);
            var appDomain = AppDomain.CreateDomain("Cassette-MSBuild-AppDomain", null, setup);

            try
            {
                var commandInAppDomain = CreateCommandInAppDomain(command, appDomain);
                commandInAppDomain.Execute();
            }
            finally
            {
                AppDomain.Unload(appDomain);
            }
        }
コード例 #9
0
        public override bool Execute()
        {
            AssignPropertyDefaultsIfMissing();
            MakePathsAbsolute();

            Log.LogMessage("Source directory = {0}", Source);
            Log.LogMessage("Bin directory = {0}", Bin);
            Log.LogMessage("Output directory = {0}", Output);
            Log.LogMessage("Include other files = {0}", IncludeOtherFiles);

            // Execution will load assemblies. When running this task from a Visual Studio build, the DLLs would then be locked.
            // So we must run the command in a separate AppDomain.
            // This means the assemblies can be unlocked by unloading the new AppDomain when finished.
            CreateBundlesCommand.ExecuteInSeparateAppDomain(new CreateBundlesCommand(Source, Bin, Output, IncludeOtherFiles, Log));

            return(true);
        }
コード例 #10
0
        static CreateBundlesCommand CreateCommandInAppDomain(CreateBundlesCommand command, AppDomain appDomain)
        {
            var assemblyLocation = typeof(CreateBundlesCommand).Assembly.Location;
            var typeString       = typeof(CreateBundlesCommand).FullName;

            // This is like calling
            //   new CreateBundlesCommand(command.source, command.bin, command.output, command.logInformation, command.logError);
            // but the object lives in the other AppDomain.

            var constructorArguments = new object[] { command.source, command.bin, command.output, command.appVirtualPath, command.includeRawFiles, command.taskLoggingHelper };

#if NET35
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                assemblyLocation,
                typeString,
                false,
                0,
                null,
                constructorArguments,
                null,
                null,
                null
                );
#else
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                assemblyLocation,
                typeString,
                false,
                0,
                null,
                constructorArguments,
                null,
                null
                );
#endif
            var unwrappedObject = objectHandle.Unwrap();

            AppDomain.CurrentDomain.AssemblyResolve += OnCurrentDomainAssemblyResolve;
            var typedObject = (CreateBundlesCommand)unwrappedObject;
            AppDomain.CurrentDomain.AssemblyResolve -= OnCurrentDomainAssemblyResolve;

            return(typedObject);
        }
コード例 #11
0
        static CreateBundlesCommand CreateCommandInAppDomain(CreateBundlesCommand command, AppDomain appDomain)
        {
            // This is like calling
            //   new CreateBundlesCommand(command.source, command.bin, command.output);
            // but the object lives in the other AppDomain.

            var constructorArguments = new object[] { command.source, command.bin, command.output, command.includeRawFiles };
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                typeof(CreateBundlesCommand).Assembly.Location,
                typeof(CreateBundlesCommand).FullName,
                false,
                0,
                null,
                constructorArguments,
                null,
                null
            );
            return (CreateBundlesCommand)objectHandle.Unwrap();
        }
コード例 #12
0
        static CreateBundlesCommand CreateCommandInAppDomain(CreateBundlesCommand command, AppDomain appDomain)
        {
            // This is like calling
            //   new CreateBundlesCommand(command.source, command.bin, command.output);
            // but the object lives in the other AppDomain.

            var constructorArguments = new object[] { command.source, command.bin, command.output, command.includeRawFiles };
            var objectHandle         = Activator.CreateInstanceFrom(
                appDomain,
                typeof(CreateBundlesCommand).Assembly.Location,
                typeof(CreateBundlesCommand).FullName,
                false,
                0,
                null,
                constructorArguments,
                null,
                null
                );

            return((CreateBundlesCommand)objectHandle.Unwrap());
        }
コード例 #13
0
        public CreateBundlesWithRawFilesTests()
        {
            root = new TempDirectory();

            CreateDirectory("source");
            CreateDirectory("source\\bin");
            CreateDirectory("output");

            WriteFile("source\\test.css", @"p { background: url(test.png); } .other { background: url(notfound.png); }");
            WriteFile("source\\test.png", "image");

            var configurationDll = CompileConfigurationDll();

            File.Move(configurationDll, PathUtilities.Combine(root, "source", "bin", "test.dll"));
            File.Copy("Cassette.dll", PathUtilities.Combine(root, "source", "bin", "Cassette.dll"));
            File.Copy("Cassette.pdb", PathUtilities.Combine(root, "source", "bin", "Cassette.pdb"));
            File.Copy("AjaxMin.dll", PathUtilities.Combine(root, "source", "bin", "AjaxMin.dll"));
#if NET35
            File.Copy("Iesi.Collections.dll", PathUtilities.Combine(root, "source", "bin", "Iesi.Collections.dll"));
#endif
            buildEngine = new BuildEngineStub();
            var task = new CreateBundles
            {
                BuildEngine = buildEngine
            };

            var taskLoggingHelper = new TaskLoggingHelper(task);

            var command = new CreateBundlesCommand(
                PathUtilities.Combine(root, "source"),
                PathUtilities.Combine(root, "source", "bin"),
                PathUtilities.Combine(root, "output"),
                "/",
                true,
                taskLoggingHelper
                );

            CreateBundlesCommand.ExecuteInSeparateAppDomain(command);
        }
コード例 #14
0
        static CreateBundlesCommand CreateCommandInAppDomain(CreateBundlesCommand command, AppDomain appDomain)
        {
            // This is like calling
            //   new CreateBundlesCommand(command.source, command.bin, command.output, command.logInformation, command.logError);
            // but the object lives in the other AppDomain.

            var constructorArguments = new object[] { command.source, command.bin, command.output, command.appVirtualPath, command.includeRawFiles, command.taskLoggingHelper };

#if NET35
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                typeof(CreateBundlesCommand).Assembly.Location,
                typeof(CreateBundlesCommand).FullName,
                false,
                0,
                null,
                constructorArguments,
                null,
                null,
                null
                );
#else
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                typeof(CreateBundlesCommand).Assembly.Location,
                typeof(CreateBundlesCommand).FullName,
                false,
                0,
                null,
                constructorArguments,
                null,
                null
                );
#endif
            return((CreateBundlesCommand)objectHandle.Unwrap());
        }
コード例 #15
0
        static CreateBundlesCommand CreateCommandInAppDomain(CreateBundlesCommand command, AppDomain appDomain)
        {
            // This is like calling
            //   new CreateBundlesCommand(command.source, command.bin, command.output, command.logInformation, command.logError);
            // but the object lives in the other AppDomain.

            var constructorArguments = new object[] { command.source, command.bin, command.output, command.appVirtualPath, command.includeRawFiles, command.taskLoggingHelper };

            #if NET35
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                typeof(CreateBundlesCommand).Assembly.Location,
                typeof(CreateBundlesCommand).FullName,
                false,
                0,
                null,
                constructorArguments,
                null,
                null,
                null
            );
            #else
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                typeof(CreateBundlesCommand).Assembly.Location,
                typeof(CreateBundlesCommand).FullName,
                false,
                0,
                null,
                constructorArguments,
                null,
                null
            );
            #endif
            return (CreateBundlesCommand)objectHandle.Unwrap();
        }
コード例 #16
0
        static CreateBundlesCommand CreateCommandInAppDomain(CreateBundlesCommand command, AppDomain appDomain)
        {
            var assemblyLocation = typeof(CreateBundlesCommand).Assembly.Location;
            var typeString = typeof(CreateBundlesCommand).FullName;

            // This is like calling
            //   new CreateBundlesCommand(command.source, command.bin, command.output, command.logInformation, command.logError);
            // but the object lives in the other AppDomain.

            var constructorArguments = new object[] { command.source, command.bin, command.output, command.appVirtualPath, command.includeRawFiles, command.taskLoggingHelper };
            
#if NET35
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                assemblyLocation,
                typeString,
                false,
                0,
                null,
                constructorArguments,
                null,
                null,
                null
            );
#else
            var objectHandle = Activator.CreateInstanceFrom(
                appDomain,
                assemblyLocation,
                typeString,
                false,
                0,
                null,
                constructorArguments,
                null,
                null
            );
#endif
            var unwrappedObject = objectHandle.Unwrap();

            AppDomain.CurrentDomain.AssemblyResolve += OnCurrentDomainAssemblyResolve;
            var typedObject = (CreateBundlesCommand)unwrappedObject;
            AppDomain.CurrentDomain.AssemblyResolve -= OnCurrentDomainAssemblyResolve;

            return typedObject;
        }