Пример #1
0
 static void AssignConfigurationFile(CreateBundlesCommand command, AppDomainSetup setup)
 {
     var configFilename = Path.Combine(command.source, "web.config");
     if (File.Exists(configFilename))
     {
         setup.ConfigurationFile = configFilename;
     }
 }
Пример #2
0
        static AppDomainSetup CreateAppDomainSetup(CreateBundlesCommand command)
        {
            var setup = new AppDomainSetup
            {
                ApplicationBase = command.bin,
                ShadowCopyFiles = "true"
            };

            AssignConfigurationFile(command, setup);
            return setup;
        }
Пример #3
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);
            }
        }
Пример #4
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;
        }