configurationmsbuildweb-config

What setting in MSBuild prints the ProjectGuid?


When creating a simple web project it contains the 'ProjectGuid' as a comment at the bottom of the web.config file. Where is it set that this comment is added (presumably something in MSBuild)? Is it possible to stop that comment getting added?

<?xml version="1.0" encoding="utf-8"?>

<configuration>
    <system.webServer>
       
        // config....

    </system.webServer>
</configuration>
<!--ProjectGuid: <SOME GUID>--> // what adds this???

Solution

  • This can be caused by the .NET SDK and .NET CLI telemetry.

    If you disable it by using the Opt-Out environment variable, it should stop generating this GUID:

    How to opt out

    The .NET SDK telemetry feature is enabled by default for Microsoft distributions of the SDK. To opt out of the telemetry feature, set the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 or true.

    A single telemetry entry is also sent by the .NET SDK installer when a successful installation happens. To opt out, set the DOTNET_CLI_TELEMETRY_OPTOUT environment variable before you install the .NET SDK.

    The code that writes the Guid is in Microsoft.NET.Sdk.Publish.Tasks.WebConfigTelemetry:

    public static XDocument AddTelemetry(XDocument webConfig, string projectGuid, bool ignoreProjectGuid, string solutionFileFullPath, string projectFileFullPath)
    {
        try
        {
            bool isCLIOptOutEnabled = EnvironmentHelper.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, defaultValue: CompileOptions.TelemetryOptOutDefault);
            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;
    }
    

    Per the above code, IgnoreProjectGuid should also work if you still want the telemetry, but I've tested using the telemetry opt-out.