public ClientBuildManager(string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter, TypeDescriptionProvider typeDescriptionProvider) { this._lock = new object(); if (parameter == null) { parameter = new ClientBuildManagerParameter(); } this.InitializeCBMTDPBridge(typeDescriptionProvider); if (!string.IsNullOrEmpty(appPhysicalTargetDir)) { parameter.PrecompilationFlags |= PrecompilationFlags.Clean; } this._hostingParameters = new HostingEnvironmentParameters(); this._hostingParameters.HostingFlags = HostingEnvironmentFlags.ClientBuildManager | HostingEnvironmentFlags.DontCallAppInitialize; this._hostingParameters.ClientBuildManagerParameter = parameter; this._hostingParameters.PrecompilationTargetPhysicalDirectory = appPhysicalTargetDir; if (typeDescriptionProvider != null) { this._hostingParameters.HostingFlags |= HostingEnvironmentFlags.SupportsMultiTargeting; } if (appVirtualDir[0] != '/') { appVirtualDir = "/" + appVirtualDir; } if (((appPhysicalSourceDir == null) && appVirtualDir.StartsWith("/IISExpress/", StringComparison.OrdinalIgnoreCase)) && (appVirtualDir.Length > "/IISExpress/".Length)) { int index = appVirtualDir.IndexOf('/', "/IISExpress/".Length); if (index > 0) { this._hostingParameters.IISExpressVersion = appVirtualDir.Substring("/IISExpress/".Length, index - "/IISExpress/".Length); appVirtualDir = appVirtualDir.Substring(index); } } this.Initialize(VirtualPath.CreateNonRelative(appVirtualDir), appPhysicalSourceDir); }
public void Defaults () { ClientBuildManagerParameter p = new ClientBuildManagerParameter (); Assert.AreEqual (PrecompilationFlags.Default, p.PrecompilationFlags, "A1"); Assert.IsNull (p.StrongNameKeyContainer, "A2"); Assert.IsNull (p.StrongNameKeyFile, "A3"); }
/* * Creates an instance of the PrecompilationManager. * appPhysicalSourceDir points to the physical root of the application (e.g "c:\myapp") * appVirtualDir is the virtual path to the app root. It can be anything (e.g. "/dummy"), * but ideally it should match the path later given to Cassini, in order for * compilation that happens here to be reused there. * appPhysicalTargetDir is the directory where the precompiled site is placed * typeDescriptionProvider is the provider used for retrieving type * information for multi-targeting */ public ClientBuildManager(string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter, TypeDescriptionProvider typeDescriptionProvider) { if (parameter == null) { parameter = new ClientBuildManagerParameter(); } InitializeCBMTDPBridge(typeDescriptionProvider); // Always build clean in precompilation for deployment mode, // since building incrementally raises all kind of issues (VSWhidbey 382954). if (!String.IsNullOrEmpty(appPhysicalTargetDir)) { parameter.PrecompilationFlags |= PrecompilationFlags.Clean; } _hostingParameters = new HostingEnvironmentParameters(); _hostingParameters.HostingFlags = HostingEnvironmentFlags.DontCallAppInitialize | HostingEnvironmentFlags.ClientBuildManager; _hostingParameters.ClientBuildManagerParameter = parameter; _hostingParameters.PrecompilationTargetPhysicalDirectory = appPhysicalTargetDir; if (typeDescriptionProvider != null) { _hostingParameters.HostingFlags |= HostingEnvironmentFlags.SupportsMultiTargeting; } // Make sure the app virtual dir starts with / if (appVirtualDir[0] != '/') { appVirtualDir = "/" + appVirtualDir; } if (appPhysicalSourceDir == null && appVirtualDir.StartsWith(IISExpressPrefix, StringComparison.OrdinalIgnoreCase) && appVirtualDir.Length > IISExpressPrefix.Length) { // appVirtualDir should have the form "/IISExpress/<version>/LM/W3SVC/", // and we will try to extract the version. The version will be validated // when it is passed to IISVersionHelper..ctor. int endSlash = appVirtualDir.IndexOf('/', IISExpressPrefix.Length); if (endSlash > 0) { _hostingParameters.IISExpressVersion = appVirtualDir.Substring(IISExpressPrefix.Length, endSlash - IISExpressPrefix.Length); appVirtualDir = appVirtualDir.Substring(endSlash); } } Initialize(VirtualPath.CreateNonRelative(appVirtualDir), appPhysicalSourceDir); }
public ClientBuildManager(string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter, System.ComponentModel.TypeDescriptionProvider typeDescriptionProvider) { }
public ClientBuildManager(string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter) : this(appVirtualDir, appPhysicalSourceDir, appPhysicalTargetDir, parameter, null) { }
public ClientBuildManager(string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter) : this(appVirtualDir, appPhysicalSourceDir, appPhysicalTargetDir) { //build_params = parameter; }
/* * Creates an instance of the PrecompilationManager. * appPhysicalSourceDir points to the physical root of the application (e.g "c:\myapp") * appVirtualDir is the virtual path to the app root. It can be anything (e.g. "/dummy"), * but ideally it should match the path later given to Cassini, in order for * compilation that happens here to be reused there. * appPhysicalTargetDir is the directory where the precompiled site is placed * flags determines the behavior of the precompilation */ public ClientBuildManager(string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter) : this(appVirtualDir, appPhysicalSourceDir, appPhysicalTargetDir, parameter, typeDescriptionProvider : null) { }
/* * Creates an instance of the PrecompilationManager. * appPhysicalSourceDir points to the physical root of the application (e.g "c:\myapp") * appVirtualDir is the virtual path to the app root. It can be anything (e.g. "/dummy"), * but ideally it should match the path later given to Cassini, in order for * compilation that happens here to be reused there. * appPhysicalTargetDir is the directory where the precompiled site is placed * flags determines the behavior of the precompilation */ public ClientBuildManager(string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter) : this(appVirtualDir, appPhysicalSourceDir, appPhysicalTargetDir, parameter, typeDescriptionProvider: null) { }
/* * Creates an instance of the PrecompilationManager. * appPhysicalSourceDir points to the physical root of the application (e.g "c:\myapp") * appVirtualDir is the virtual path to the app root. It can be anything (e.g. "/dummy"), * but ideally it should match the path later given to Cassini, in order for * compilation that happens here to be reused there. * appPhysicalTargetDir is the directory where the precompiled site is placed * typeDescriptionProvider is the provider used for retrieving type * information for multi-targeting */ public ClientBuildManager(string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter, TypeDescriptionProvider typeDescriptionProvider) { if (parameter == null) { parameter = new ClientBuildManagerParameter(); } InitializeCBMTDPBridge(typeDescriptionProvider); // Always build clean in precompilation for deployment mode, // since building incrementally raises all kind of issues (VSWhidbey 382954). if (!String.IsNullOrEmpty(appPhysicalTargetDir)) { parameter.PrecompilationFlags |= PrecompilationFlags.Clean; } _hostingParameters = new HostingEnvironmentParameters(); _hostingParameters.HostingFlags = HostingEnvironmentFlags.DontCallAppInitialize | HostingEnvironmentFlags.ClientBuildManager; _hostingParameters.ClientBuildManagerParameter = parameter; _hostingParameters.PrecompilationTargetPhysicalDirectory = appPhysicalTargetDir; if (typeDescriptionProvider != null) { _hostingParameters.HostingFlags |= HostingEnvironmentFlags.SupportsMultiTargeting; } // Make sure the app virtual dir starts with / if (appVirtualDir[0] != '/') appVirtualDir = "/" + appVirtualDir; if (appPhysicalSourceDir == null && appVirtualDir.StartsWith(IISExpressPrefix, StringComparison.OrdinalIgnoreCase) && appVirtualDir.Length > IISExpressPrefix.Length) { // appVirtualDir should have the form "/IISExpress/<version>/LM/W3SVC/", // and we will try to extract the version. The version will be validated // when it is passed to IISVersionHelper..ctor. int endSlash = appVirtualDir.IndexOf('/', IISExpressPrefix.Length); if (endSlash > 0) { _hostingParameters.IISExpressVersion = appVirtualDir.Substring(IISExpressPrefix.Length, endSlash - IISExpressPrefix.Length); appVirtualDir = appVirtualDir.Substring(endSlash); } } Initialize(VirtualPath.CreateNonRelative(appVirtualDir), appPhysicalSourceDir); }
/// <summary> /// Generates the client proxies. /// </summary> /// <remarks> /// This method validates the presence of the necessary input server assemblies and /// then invokes the code generation logic to create a file containing the client /// proxies for the discovered server's Business Objects. If the file already exists /// and is newer than the inputs, this method does nothing. /// <para>In all success paths, the client proxy file will be added to the list of generated /// files so the custom targets file can add them to the @Compile collection.</para> /// </remarks> internal void GenerateClientProxies() { IEnumerable<string> assemblies = this.GetServerAssemblies(); IEnumerable<string> references = this.GetReferenceAssemblies(); // We will load all input and reference assemblies IEnumerable<string> assembliesToLoad = assemblies.Concat(references); // It is a failure if any of the reference assemblies are missing if (!this.EnsureAssembliesExist(references)) { return; } // Obtain the name of the output assembly from the server project // (it is currently a collection to be consistent with MSBuild item collections). // If there is no output assembly, log a warning. // We consider this non-fatal because an Intellisense build can trivially // encounter this immediately after creating a new Open Ria Services application string assemblyFile = assemblies.FirstOrDefault(); if (string.IsNullOrEmpty(assemblyFile) || !File.Exists(assemblyFile)) { string serverProjectFile = Path.GetFileName(this.ServerProjectPath); this.LogWarning(string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_No_Input_Assemblies, serverProjectFile)); return; } // Make it an absolute path and append the language-specific extension string generatedFileName = Path.Combine(this.GeneratedCodePath, this.GenerateProxyFileName(assemblyFile)); // We maintain cached lists of references we used in prior builds. // Determine whether our current inputs are different from the last build that generated code. bool serverReferencesChanged = this.HaveReferencesChanged(this.ServerReferenceListPath(), assembliesToLoad, this.ServerProjectDirectory); bool clientReferencesChanged = this.HaveReferencesChanged(this.ClientReferenceListPath(), this.ClientReferenceAssembliesNormalized, this.ClientProjectDirectory); // Any change in the assembly references for either client or server are grounds to re-gen code. // Developer note -- we use the fact that the inputs have changed to trigger the full code-gen pass. bool needToGenerate = serverReferencesChanged || clientReferencesChanged; // Also trigger code-gen if the generated file is absent or empty. // Technically, the reference-change test is enough, but experience has shown users // manually delete the GeneratedCode folder and expect the next build to recreate it. // Therefore, its absence always triggers a code-gen pass, even though this has the // negative perf impact of causing a full code gen pass everytime until errors have been // resolved. if (!needToGenerate) { FileInfo fileInfo = new FileInfo(generatedFileName); bool fileExists = fileInfo.Exists; needToGenerate = (!fileExists || (fileInfo.Length == 0)); // If we determine the generated // file has been touched since we last analyzed our server references, it is an indication // the user modified the generated file. So force a code gen and // force a rewrite of the server reference file to short circuit this same code next build. if (!needToGenerate && fileExists && File.Exists(this.ServerReferenceListPath())) { if (File.GetLastWriteTime(generatedFileName) > File.GetLastWriteTime(this.ServerReferenceListPath())) { needToGenerate = true; serverReferencesChanged = true; } } } // If we need to generate the file, do that now if (needToGenerate) { // Warn the user if the server assembly has no PDB this.WarnIfNoPdb(assemblyFile); string generatedFileContent = string.Empty; // We override the default parameter to ask for ForceDebug, otherwise the PDB is not copied. ClientBuildManagerParameter cbmParameter = new ClientBuildManagerParameter() { PrecompilationFlags = PrecompilationFlags.ForceDebug, }; string sourceDir = this.ServerProjectDirectory; string targetDir = null; using (ClientBuildManager cbm = new ClientBuildManager(/* appVDir */ "/", sourceDir, targetDir, cbmParameter)) { // Capture the list of assemblies to load into an array to marshal across AppDomains string[] assembliesToLoadArray = assembliesToLoad.ToArray(); // Create the list of options we will pass to the generator. // This instance is serializable and can cross AppDomains ClientCodeGenerationOptions options = new ClientCodeGenerationOptions() { Language = this.Language, ClientFrameworkPath = this.ClientFrameworkPath, ClientRootNamespace = this.ClientProjectRootNamespace, ServerRootNamespace = this.ServerProjectRootNameSpace, ClientProjectPath = this.ClientProjectPath, ServerProjectPath = this.ServerProjectPath, IsApplicationContextGenerationEnabled = this.IsClientApplicationAsBool, UseFullTypeNames = this.UseFullTypeNamesAsBool, ClientProjectTargetPlatform = this.ClientTargetPlatform, }; // The other AppDomain gets a logger that will log back to this AppDomain CrossAppDomainLogger logger = new CrossAppDomainLogger((ILoggingService)this); // Compose the parameters we will pass to the other AppDomain to create the SharedCodeService SharedCodeServiceParameters sharedCodeServiceParameters = this.CreateSharedCodeServiceParameters(assembliesToLoadArray); // Surface a HttpRuntime initialization error that would otherwise manifest as a NullReferenceException // This can occur when the build environment is configured incorrectly if (System.Web.Hosting.HostingEnvironment.InitializationException != null) { throw new InvalidOperationException( Resource.HttpRuntimeInitializationError, System.Web.Hosting.HostingEnvironment.InitializationException); } // Create the "dispatcher" in the 2nd AppDomain. // This object will find and invoke the appropriate code generator using (ClientCodeGenerationDispatcher dispatcher = (ClientCodeGenerationDispatcher)cbm.CreateObject(typeof(ClientCodeGenerationDispatcher), false)) { // Transfer control to the dispatcher in the 2nd AppDomain to locate and invoke // the appropriate code generator. generatedFileContent = dispatcher.GenerateCode(options, sharedCodeServiceParameters, logger, this.CodeGeneratorName); } } // Tell the user where we are writing the generated code if (!string.IsNullOrEmpty(generatedFileContent)) { this.LogMessage(string.Format(CultureInfo.CurrentCulture, Resource.Writing_Generated_Code, generatedFileName)); } // If VS is hosting us, write to its TextBuffer, else simply write to disk // If the file is empty, delete it. this.WriteOrDeleteFileToVS(generatedFileName, generatedFileContent, /*forceWriteToFile*/ false); } else { // Log a message telling user we are skipping code gen because the inputs are older than the generated code this.LogMessage(string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Skipping_CodeGen, generatedFileName)); } // We unconditionally declare the file was generated if it exists // on disk after this method finishes, even if it was not modified. // This permits the targets file to add it to the @COMPILE collection. // This also prevents adding it to the list if it was deleted above if (File.Exists(generatedFileName)) { this.AddGeneratedFile(generatedFileName); } // Write out reference lists if they have changed if (serverReferencesChanged) { this.WriteReferenceList(this.ServerReferenceListPath(), assembliesToLoad, this.ServerProjectDirectory); } if (clientReferencesChanged) { this.WriteReferenceList(this.ClientReferenceListPath(), this.ClientReferenceAssembliesNormalized, this.ClientProjectDirectory); } return; }
public ClientBuildManager (string appVirtualDir, string appPhysicalSourceDir, string appPhysicalTargetDir, ClientBuildManagerParameter parameter) : this (appVirtualDir, appPhysicalSourceDir, appPhysicalTargetDir) { //build_params = parameter; }
/// <summary> /// Handles the deployment of a portal /// </summary> private void DeployPortal() { string portalName = Manifest.PortalName; PortalApplication application = PortalApplication.Get(portalName); if (application != null) { var deployment = new Sage.Platform.Deployment.Deployment { DeploymentName = portalName }; InitializeDeployment(deployment, application.Id.ToString()); var wrapper = new DeploymentCallbackWrapper(); try { log.Info(Resources.log_deployment_started); wrapper.DeployPortal(deployment); log.Info(Resources.log_deployment_ended); var callback = new PrecompileBuildManagerCallback(); var buildParameter = new ClientBuildManagerParameter { PrecompilationFlags = PrecompilationFlags.OverwriteTarget | PrecompilationFlags.Clean | PrecompilationFlags.CodeAnalysis }; if (Manifest.Precompile) { log.Info(Resources.log_precompile_started); DeploymentUtil util = new DeploymentUtil(); util.PrecompileSite(callback, buildParameter, Manifest.DeploymentPath, null, null, "/" + portalName, false); log.Info(Resources.log_precompile_finished); } } catch (Exception ex) { log.Error(Resources.error_deploying_portal, ex); } } }
public ClientBuildManagerWrapper(string webApplicationName, string webApplicationPhysicalPath, string preCompileOutputpath, ClientBuildManagerParameter parameter) { _buildManager = new ClientBuildManager(webApplicationName, webApplicationPhysicalPath, preCompileOutputpath, parameter); }
public static int Main(string[] args) { _excludedVirtualPaths = new List <string>(); bool nologo = false; try { // Get the proper line length based on the Console window settings. // This can fail in some cases, so ignore errors, and stay with the default maxLineLength = Console.BufferWidth; } catch { } // Set the console app's UI culture (VSWhidbey 316444) SetThreadUICulture(); // First, check if there is a -nologo switch for (int i = 0; i < args.Length; i++) { string currentSwitch = args[i].ToLower(CultureInfo.InvariantCulture); if (currentSwitch == "-nologo" || currentSwitch == "/nologo") { nologo = true; } } if (!nologo) { Console.WriteLine(String.Format(CultureInfo.CurrentCulture, CompilerResources.brand_text, ThisAssembly.InformationalVersion)); Console.WriteLine(CompilerResources.header_text); Console.WriteLine(CompilerResources.copyright); Console.WriteLine(); } if (args.Length == 0) { Console.WriteLine(CompilerResources.short_usage_text); return(1); } if (!ValidateArgs(args)) { return(1); } try { // ClientBuildManager automatically detects vpath vs mbpath if (_sourceVirtualDir == null) { _sourceVirtualDir = _metabasePath; } ClientBuildManagerParameter parameter = new ClientBuildManagerParameter(); parameter.PrecompilationFlags = _precompilationFlags; parameter.StrongNameKeyFile = _keyFile; parameter.StrongNameKeyContainer = _keyContainer; parameter.ExcludedVirtualPaths.AddRange(_excludedVirtualPaths); _client = new ClientBuildManager(_sourceVirtualDir, _sourcePhysicalDir, _targetPhysicalDir, parameter); _client.PrecompileApplication(new CBMCallback()); // Return 0 when successful return(0); } catch (FileLoadException e) { // If the assembly fails to be loaded because of strong name verification, // return a better error message. if ((_precompilationFlags & PrecompilationFlags.DelaySign) != 0) { PropertyInfo pInfo = typeof(FileLoadException).GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo methodInfo = pInfo.GetGetMethod(true /*nonPublic*/); uint hresult = (uint)(int)methodInfo.Invoke(e, null); if (hresult == 0x8013141A) { DumpErrors(new FileLoadException(String.Format(CultureInfo.CurrentCulture, CompilerResources.Strongname_failure, e.FileName), e.FileName, e)); return(1); } } DumpErrors(e); } catch (Exception e) { DumpErrors(e); } // Some exception happened, so return 1 return(1); }