Create a new configuration:
- Click Build then select Configuration Manager.
- Click Active solution configuration and select New.
- Type
Profile
in Name and select which configuration will be used as template (for profiling I guess Release
).
- Confirm with OK, it'll create new configurations named
Profile
for each project in your solution.
- Open properties of each project, and in the Build tab add
PROFILE
symbol in Conditional compilation symbols then save properties.
Now when you build the Profile
configuration the PROFILE
symbol will be defined. I suggest you take a look to this post too, if you automate your builds you may keep your PROFILE
symbol out of the solution using MSBuild
properties via command-line (I suppose you do not build for profiling very often).
EDIT
With configuration you can do that but it won't save you from a broken reference to Microsoft.VisualStudio.Profiler.dll
). What I suggest is to move all this code to another library that you'll ship to them compiled. There you'll expose just a method:
public static class ProfilingHelpers
{
[Conditional("PROFILE")]
public static void StartProfiling()
{
DataCollection.StartProfile(ProfileLevel.Process, DataCollection.CurrentId);
}
}
In your code you'll always call it but it'll be executed only when PROFILE
is defined (so you won't need to add a new configuration to each project but to one DLL only).