I am using the MSBuild engine to run a deployment on Team Server Database Project:
var propertyGroup = new BuildPropertyGroup();
propertyGroup .SetProperty("Configuration", "Release");
propertyGroup .SetProperty("TargetDatabase", <databasename>);
propertyGroup .SetProperty("UseSandboxSettings", "false");
propertyGroup .SetProperty("DeployToDatabase", "true");
propertyGroup .SetProperty("TargetConnectionString", LocalHostConnectionString);
new Engine().BuildProjectFile(<DBProjFile>, new[] { "Rebuild", "Deploy" }, propertyGroup);
This is being run in a setup fixture for a suite of unit tests. When run using Resharper the setup runs in a reasonable amount of time however if I Debug the tests I get loads of Trace noise in the Debug output. Most of the messages are logged at a verbose level.
I have reflected over some of the assemblies involved and found that there is a TraceSource with the name “TSData” that is created in the static class Microsoft.Data.Schema.Common.Diagnostics.TSDTrace, Microsoft.Data.Schema.Utilities.
I have tried applying the following to the app.config which has stopped any output appearing in the Debug window but the run time is unaffected:
<system.diagnostics>
<sources>
<source name="TSData" switchName="foo" />
</sources>
<switches>
<add name="foo" value="Off"/>
</switches>
</system.diagnostics>
In the logging class there is this little gem:
if (TSDTrace.Settings._traceIfDebuggerAttached && Debugger.IsAttached)
{
TSDTrace.Settings._traceToDebugOutput = true;
TSDTrace.Settings._traceLevel = TraceLevel.Verbose;
}
Where _traceIfDebuggerAttached is always true. I am hopping that I have missed something. Ultimately I would like to disable this from code but I would settle for a solution involving the app config.
EDIT
I had made a mistake, the Trace Source is in-fact “TSData” which I have amended above. I have set the log level to Off in the app.config which has prevented the output from appearing in the Debug output but the speed is still the same. It appears this issue is more specific to what I am trying to do so I have added more detail to the original question.
It seems that Microsoft.Build.BuildEngine.Engine has been deprecated, instead I should have been using Microsoft.Build.Evaluation.ProjectCollection instead.
I have changed the code to use the new object and everything works much faster and I do not need to try and disable any logging via systems diagnostics in the log file. The code now reads: