protected override void ProcessRecordCore()
        {
            if (!_solutionManager.IsSolutionOpen)
            {
                ErrorHandler.ThrowSolutionNotOpenTerminatingError();
            }

            var projects = new List <Project>();

            // if no project specified, use default
            if (ProjectName == null)
            {
                Project project = _solutionManager.DefaultProject;

                // if no default project (empty solution), throw terminating
                if (project == null)
                {
                    ErrorHandler.ThrowNoCompatibleProjectsTerminatingError();
                }

                projects.Add(project);
            }
            else
            {
                // get matching projects, expanding wildcards
                projects.AddRange(GetProjectsByName(ProjectName));
            }

            // Create a new app domain so we don't load the assemblies into the host app domain
            AppDomain domain = AppDomain.CreateDomain("domain");

            try
            {
                foreach (Project project in projects)
                {
                    var redirects = RuntimeHelpers.AddBindingRedirects(project, _fileSystemProvider, domain, _frameworkMultiTargeting);

                    // Print out what we did
                    WriteObject(redirects, enumerateCollection: true);
                }
            }
            finally
            {
                AppDomain.Unload(domain);
            }
        }
Example #2
0
        protected override void ProcessRecordCore()
        {
            Preprocess();

            CheckForSolutionOpen();

            var projects = new List <Project>();

            // if no project specified, use default
            if (ProjectName == null)
            {
                Project defaultProject = GetDefaultProject();

                // if no default project (empty solution), throw terminating
                if (defaultProject == null)
                {
                    ErrorHandler.ThrowNoCompatibleProjectsTerminatingError();
                }

                projects.Add(defaultProject);
            }
            else
            {
                // get matching projects, expanding wildcards
                projects.AddRange(GetProjectsByName(ProjectName));
            }

            // Create a new app domain so we don't load the assemblies into the host app domain
            AppDomain domain = AppDomain.CreateDomain("domain");

            try
            {
                foreach (Project project in projects)
                {
                    var projectAssembliesCache = new Dictionary <string, HashSet <string> >(StringComparer.OrdinalIgnoreCase);
                    var redirects = RuntimeHelpers.AddBindingRedirects(VsSolutionManager, project, domain, projectAssembliesCache, _frameworkMultiTargeting, this);

                    // Print out what we did
                    WriteObject(redirects, enumerateCollection: true);
                }
            }
            finally
            {
                AppDomain.Unload(domain);
            }
        }