Example #1
0
        public static XDocument AddTelemetry(XDocument webConfig, string projectGuid, bool ignoreProjectGuid, string solutionFileFullPath, string projectFileFullPath)
        {
            try
            {
                bool isCLIOptOutEnabled = EnvironmentHelper.GetEnvironmentVariableAsBool(TelemetryOptout);
                if (string.IsNullOrEmpty(projectGuid) && !ignoreProjectGuid && !isCLIOptOutEnabled)
                {
                    projectGuid = GetProjectGuidFromSolutionFile(solutionFileFullPath, projectFileFullPath);
                }

                // Add the projectGuid to web.config if it is not present. Remove ProjectGuid from web.config if opted out.
                webConfig = WebConfigTransform.AddProjectGuidToWebConfig(webConfig, projectGuid, ignoreProjectGuid);
            }
            catch
            {
                // Telemtry
            }

            return(webConfig);
        }
Example #2
0
        public override bool Execute()
        {
            Log.LogMessage(MessageImportance.Low, $"Configuring the following project for use with IIS: '{PublishDir}'");

            XDocument webConfigXml  = null;
            string    webConfigPath = Path.Combine(PublishDir, "web.config");

            if (File.Exists(webConfigPath))
            {
                Log.LogMessage($"Updating web.config at '{webConfigPath}'");

                try
                {
                    webConfigXml = XDocument.Load(webConfigPath);
                }
                catch (XmlException) { }
            }
            else
            {
                Log.LogMessage($"No web.config found. Creating '{webConfigPath}'");
            }

            if (IsAzure)
            {
                Log.LogMessage("Configuring web.config for deployment to Azure");
            }

            string    outputFile        = Path.GetFileName(TargetPath);
            XDocument transformedConfig = WebConfigTransform.Transform(webConfigXml, outputFile, IsAzure, IsPortable);

            // Add the projectGuid to web.config if it is not present.
            transformedConfig = WebConfigTransform.AddProjectGuidToWebConfig(transformedConfig, ProjectGuid, IgnoreProjectGuid);

            using (FileStream f = new FileStream(webConfigPath, FileMode.Create))
            {
                transformedConfig.Save(f);
            }

            Log.LogMessage(MessageImportance.Low, "Configuring project completed successfully");
            return(true);
        }