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);
        }
Example #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);
        }
 static void AssignConfigurationFile(CreateBundlesCommand command, AppDomainSetup setup)
 {
     var configFilename = Path.Combine(command.source, "web.config");
     if (File.Exists(configFilename))
     {
         setup.ConfigurationFile = configFilename;
     }
 }
Example #4
0
        static void AssignConfigurationFile(CreateBundlesCommand command, AppDomainSetup setup)
        {
            var configFilename = Path.Combine(command.source, "web.config");

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

            AssignConfigurationFile(command, setup);
            return(setup);
        }
 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);
     }
 }
Example #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);
            }
        }
Example #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);
        }
Example #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);
        }
        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();
        }
Example #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());
        }
        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);
        }
        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());
        }
        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();
        }
        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;
        }