public void PrecompileApplication(ClientBuildManagerCallback callback, bool forceCleanBuild)
        {
            PrecompilationFlags precompilationFlags = this._hostingParameters.ClientBuildManagerParameter.PrecompilationFlags;

            if (forceCleanBuild)
            {
                this._waitForCallBack = this._host != null;
                this.Unload();
                this._hostingParameters.ClientBuildManagerParameter.PrecompilationFlags = precompilationFlags | PrecompilationFlags.Clean;
                this.WaitForCallBack();
            }
            try
            {
                this.EnsureHostCreated();
                this._host.PrecompileApp(callback);
            }
            finally
            {
                if (forceCleanBuild)
                {
                    this._hostingParameters.ClientBuildManagerParameter.PrecompilationFlags = precompilationFlags;
                }
                if (callback != null)
                {
                    RemotingServices.Disconnect(callback);
                }
            }
        }
        public void PrecompileApplication(ClientBuildManagerCallback callback, bool forceCleanBuild)
        {
            Debug.Trace("CBM", "PrecompileApplication");

            PrecompilationFlags savedFlags = _hostingParameters.ClientBuildManagerParameter.PrecompilationFlags;

            if (forceCleanBuild)
            {
                // If there was a previous host, it will be unloaded by CBM and we will wait for the callback.
                // If there was no previous host, we don't do any waiting.
                // DevDiv 46290
                _waitForCallBack = _host != null;

                Debug.Trace("CBM", "Started Unload");
                // Unload the existing appdomain so the new one will be created with the clean flag
                Unload();

                _hostingParameters.ClientBuildManagerParameter.PrecompilationFlags =
                    savedFlags | PrecompilationFlags.Clean;

                WaitForCallBack();
            }

            try {
                EnsureHostCreated();
                _host.PrecompileApp(callback, _hostingParameters.ClientBuildManagerParameter.ExcludedVirtualPaths);
            }
            finally {
                if (forceCleanBuild)
                {
                    // Revert precompilationFlags
                    _hostingParameters.ClientBuildManagerParameter.PrecompilationFlags = savedFlags;
                }
                // DevDiv 180798. We are returning null in ClientBuildManagerCallback.InitializeLifetimeService,
                // so we need to manually disconnect the instance so that it will be released.
                if (callback != null)
                {
                    RemotingServices.Disconnect(callback);
                }
            }
        }
Exemple #3
0
        private static bool ValidateAndSetArguments(string[] args)
        {
            try
            {
                if (args.Length > 0)
                {
                    _vPath = args[0];
                }
                else
                {
                    _vPath = (string)AppSettingsExpressionBuilder.GetAppSetting
                                 ("virtualDirectory");
                }

                if (args.Length > 1)
                {
                    _pPath = args[1];
                }
                else
                {
                    _pPath = (string)AppSettingsExpressionBuilder.GetAppSetting
                                 ("physicalDirectory");
                }

                if (args.Length > 2)
                {
                    _tPath = args[2];
                }
                else
                {
                    _tPath = (string)AppSettingsExpressionBuilder.GetAppSetting
                                 ("targetDirectory");
                }

                if (args.Length > 3)
                {
                    string[] precompFlags = args[3].Split('|');
                    foreach (string flag in precompFlags)
                    {
                        _flags |= (PrecompilationFlags)Enum.Parse
                                      (typeof(PrecompilationFlags), flag.Trim());
                    }
                }
                else
                {
                    _flags = PrecompilationFlags.Clean |
                             PrecompilationFlags.ForceDebug;
                }

                if (args.Length > 4)
                {
                    _keyContainer = args[4];
                }

                return(true);
            }
            catch (Exception e)
            {
                OutputErrorList(e);
            }
            return(false);
        }
        //
        // Precompilation related code
        //

        internal void SetPrecompilationInfo(HostingEnvironmentParameters hostingParameters) {

            if (hostingParameters == null || hostingParameters.ClientBuildManagerParameter == null)
                return;

            _precompilationFlags = hostingParameters.ClientBuildManagerParameter.PrecompilationFlags;

            _strongNameKeyFile = hostingParameters.ClientBuildManagerParameter.StrongNameKeyFile;
            _strongNameKeyContainer = hostingParameters.ClientBuildManagerParameter.StrongNameKeyContainer;

            // Check if we're precompiling to a target directory
            _precompTargetPhysicalDir = hostingParameters.PrecompilationTargetPhysicalDirectory;
            if (_precompTargetPhysicalDir == null)
                return;

            // Check if the target dir already exists and is not empty
            if (Util.IsNonEmptyDirectory(_precompTargetPhysicalDir)) {

                // If it's not empty and OverwriteTarget is off, fail
                if ((_precompilationFlags & PrecompilationFlags.OverwriteTarget) == 0) {
                    throw new HttpException(SR.GetString(SR.Dir_not_empty));
                }

                // Does it contain the precomp marker file
                bool updatable;
                bool precompiled = ReadPrecompMarkerFile(_precompTargetPhysicalDir, out updatable);

                // If not, refuse to delete the directory, even if OverwriteTarget is on (VSWhidbey 425095)
                if (!precompiled) {
                    throw new HttpException(SR.GetString(SR.Dir_not_empty_not_precomp));
                }

                // The OverwriteTarget flag was specified, so delete the directory
                if (!DeletePrecompTargetDirectory()) {
                    // If we failed to delete it, sleep 250 ms and try again, in case there is
                    // an appdomain in the process of shutting down (the shut down would
                    // have been triggered by the first delete attempt)
                    Debug.Trace("BuildManager", "Failed to delete " + _precompTargetPhysicalDir + ".  Sleeping and trying once more...");
                    Thread.Sleep(250);

                    if (!DeletePrecompTargetDirectory()) {
                        Debug.Trace("BuildManager", "Failed to delete " + _precompTargetPhysicalDir + ".  Sleeping and trying once more...");
                        // Try again after 1 second.
                        Thread.Sleep(1000);

                        // If we still couldn't delete it, fail
                        if (!DeletePrecompTargetDirectory()) {
                            throw new HttpException(SR.GetString(SR.Cant_delete_dir));
                        }
                    }
                }
            }

            // Create a marker file to mark the fact that this is a precompiled app
            CreatePrecompMarkerFile();
        }
Exemple #5
0
        private static bool ValidateArgs(string[] args)
        {
            if (args.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < args.Length; i++)
            {
                string currentArg = args[i];

                // If it's not a switch, expect the target path
                if (currentArg[0] != '/' && currentArg[0] != '-')
                {
                    if (_targetPhysicalDir == null)
                    {
                        _targetPhysicalDir = currentArg;
                        _targetPhysicalDir = GetFullPath(_targetPhysicalDir);
                        if (_targetPhysicalDir == null)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        DumpError("1001", String.Format(CultureInfo.CurrentCulture, CompilerResources.unexpected_param, currentArg));
                        return(false);
                    }

                    continue;
                }

                string currentSwitch = currentArg.Substring(1).ToLower(CultureInfo.InvariantCulture);

                switch (currentSwitch)
                {
                case "?":
                    DisplayUsage();
                    return(false);

                case "m":
                    _metabasePath = GetNextArgument(args, ref i);
                    if (_metabasePath == null)
                    {
                        return(false);
                    }
                    break;

                case "v":
                    _sourceVirtualDir = GetNextArgument(args, ref i);
                    if (_sourceVirtualDir == null)
                    {
                        return(false);
                    }

                    if (!IsValidVirtualPath(_sourceVirtualDir))
                    {
                        DumpError("1011", String.Format(CultureInfo.CurrentCulture, CompilerResources.invalid_vpath, _sourceVirtualDir));
                        return(false);
                    }
                    break;

                case "p":
                    _sourcePhysicalDir = GetNextArgument(args, ref i);
                    if (_sourcePhysicalDir == null)
                    {
                        return(false);
                    }
                    _sourcePhysicalDir = GetFullPath(_sourcePhysicalDir);
                    if (_sourcePhysicalDir == null)
                    {
                        return(false);
                    }

                    if (!Directory.Exists(_sourcePhysicalDir))
                    {
                        DumpError("1003", String.Format(CultureInfo.CurrentCulture, CompilerResources.dir_not_exist, _sourcePhysicalDir));
                        return(false);
                    }
                    break;

                case "x":
                    string path = GetNextArgument(args, ref i);
                    if (path == null)
                    {
                        return(false);
                    }
                    _excludedVirtualPaths.Add(path);
                    break;

                case "u":
                    _precompilationFlags |= PrecompilationFlags.Updatable;
                    break;

                case "f":
                    _precompilationFlags |= PrecompilationFlags.OverwriteTarget;
                    break;

                case "d":
                    _precompilationFlags |= PrecompilationFlags.ForceDebug;
                    break;

                case "c":
                    _precompilationFlags |= PrecompilationFlags.Clean;
                    break;

                case "nologo":
                    // Just ignore it since it was handled early on
                    break;

                case "errorstack":
                    _showErrorStack = true;
                    break;

                case "keyfile":
                    _keyFile = GetNextArgument(args, ref i);
                    if (_keyFile == null)
                    {
                        return(false);
                    }

                    if (!File.Exists(_keyFile))
                    {
                        DumpError("1012", String.Format(CultureInfo.CurrentCulture, CompilerResources.invalid_keyfile, _keyFile));
                        return(false);
                    }

                    _keyFile = Path.GetFullPath(_keyFile);
                    break;

                case "keycontainer":
                    _keyContainer = GetNextArgument(args, ref i);
                    if (_keyContainer == null)
                    {
                        return(false);
                    }
                    break;

                case "aptca":
                    _precompilationFlags |= PrecompilationFlags.AllowPartiallyTrustedCallers;
                    break;

                case "delaysign":
                    _precompilationFlags |= PrecompilationFlags.DelaySign;
                    break;

                case "fixednames":
                    _precompilationFlags |= PrecompilationFlags.FixedNames;
                    break;

                default:
                    DumpError("1004", String.Format(CultureInfo.CurrentCulture, CompilerResources.unknown_switch, currentArg));
                    return(false);
                }
            }

            // There must be exactly one of -m and -v
            if ((_sourceVirtualDir == null) == (_metabasePath == null))
            {
                DumpError("1005", CompilerResources.need_m_or_v);
                return(false);
            }

            // There must be exactly one of -m and -p
            if (_sourcePhysicalDir != null && _metabasePath != null)
            {
                DumpError("1006", CompilerResources.no_m_and_p);
                return(false);
            }

            if ((_precompilationFlags & PrecompilationFlags.Updatable) != 0 && _targetPhysicalDir == null)
            {
                DumpError("1007", String.Format(CultureInfo.CurrentCulture, CompilerResources.flag_requires_target, "u"));
                return(false);
            }

            if ((_precompilationFlags & PrecompilationFlags.OverwriteTarget) != 0 && _targetPhysicalDir == null)
            {
                DumpError("1008", String.Format(CultureInfo.CurrentCulture, CompilerResources.flag_requires_target, "f"));
                return(false);
            }

            if ((_precompilationFlags & PrecompilationFlags.ForceDebug) != 0 && _targetPhysicalDir == null)
            {
                DumpError("1009", String.Format(CultureInfo.CurrentCulture, CompilerResources.flag_requires_target, "d"));
                return(false);
            }

            if (_keyFile != null && _targetPhysicalDir == null)
            {
                DumpError("1017", String.Format(CultureInfo.CurrentCulture, CompilerResources.flag_requires_target, "keyfile"));
                return(false);
            }

            if (_keyContainer != null && _targetPhysicalDir == null)
            {
                DumpError("1018", String.Format(CultureInfo.CurrentCulture, CompilerResources.flag_requires_target, "keycontainer"));
                return(false);
            }

            if ((_precompilationFlags & PrecompilationFlags.FixedNames) != 0 && _targetPhysicalDir == null)
            {
                DumpError("1019", String.Format(CultureInfo.CurrentCulture, CompilerResources.flag_requires_target, "fixednames"));
                return(false);
            }

            if ((_precompilationFlags & PrecompilationFlags.DelaySign) != 0)
            {
                if (_keyFile == null && _keyContainer == null)
                {
                    DumpError("1013", CompilerResources.invalid_delaysign);
                    return(false);
                }
                else if (_targetPhysicalDir == null)
                {
                    DumpError("1015", String.Format(CultureInfo.CurrentCulture, CompilerResources.flag_requires_target, "delaysign"));
                    return(false);
                }
            }

            if ((_precompilationFlags & PrecompilationFlags.AllowPartiallyTrustedCallers) != 0)
            {
                if (_keyFile == null && _keyContainer == null)
                {
                    DumpError("1014", CompilerResources.invalid_aptca);
                    return(false);
                }
                else if (_targetPhysicalDir == null)
                {
                    DumpError("1016", String.Format(CultureInfo.CurrentCulture, CompilerResources.flag_requires_target, "aptca"));
                    return(false);
                }
            }

            return(true);
        }