Debugging aspects at compile-time using VS 2008
5 posts • Page 1 of 1
Debugging aspects at compile-time using VS 2008
Hello Gael,
I am looking for the quickest way to debug aspects at compile-time using VS 2008. Based on documentation I need to run msbuild with param /P:PostSharpAttachDebugger=true; so I integrated this in VS as an External Tool, and now I have it available in the Tools menu. If anyone is interested in this, here are the steps:
1. Select Tools > External Tools...
2. Click Add and enter the following data:
4. Click OK
As a result, a new menu item has been created in Tools; after clicking it, the workflow is as follows:

I am looking for the quickest way to debug aspects at compile-time using VS 2008. Based on documentation I need to run msbuild with param /P:PostSharpAttachDebugger=true; so I integrated this in VS as an External Tool, and now I have it available in the Tools menu. If anyone is interested in this, here are the steps:
1. Select Tools > External Tools...
2. Click Add and enter the following data:
- Title: Debug PostSharp Aspects [Compile-time]
- Command: %windir%\Microsoft.NET\Framework\v3.5\MSBuild.exe
- Arguments: /T:Rebuild $(ProjectFileName) /P:PostSharpAttachDebugger=true
- Initial Directory: $(ProjectDir)
4. Click OK
As a result, a new menu item has been created in Tools; after clicking it, the workflow is as follows:
- PostSharp process throws exception "Launch for user" which is displayed in VS JIT
- From the list of possible debuggers, select the VS instance in which the project is loaded and click Yes
- if VS displays a message box complaining "No symbols are loaded for any call stack frame. The source code cannot be displayed.", just click OK.
- add breakpoints in aspect's compile-time logic, if you haven't already done it
- press F5 to start debugging; if breakpoints were added correctly, they will be hit
- define a build configuration for my project: "debug aspects"
- define compilation symbol "PostSharpAttachDebugger"
(although it would be cool if these would be available out of the box, if the project references any PostSharp assembly) - select the newly defined configuration and hit F5; when I do this, the debugger attaches to PostSharp process automatically and, after this one exits, it reattaches to the original process...
You do not have the required permissions to view the files attached to this post.
- morphine
- Posts: 6
- Joined: Sat Jun 07, 2008 10:16 am
- First Name: Dan
- Last Name: M.
Re: Debugging aspects at compile-time using VS 2008
Hi Morphine,
Thank you for your contribution.
Detecting a compilation symbol "PostSharpAttachDebugger" would be possible, but I don't think it would be useful.
Another possibility is to put aspects in an separate assembly, and to configure the debugger (Project Properties / Debugger) to run msbuild as an external program. You should then use the flag
So, use the following command line:
Set the aspect project as the startup project, then use F5 as usually.
Thank you for your contribution.
Detecting a compilation symbol "PostSharpAttachDebugger" would be possible, but I don't think it would be useful.
Another possibility is to put aspects in an separate assembly, and to configure the debugger (Project Properties / Debugger) to run msbuild as an external program. You should then use the flag
- Code: Select all
/p:PostSharpUseCommandLine=False
So, use the following command line:
- Code: Select all
C:\Windows\Microsoft.NET\Framework\v....\msbuild.exe ..\AspectTest.csproj /t:Rebuild /p:PostSharpUseCommandLine=false
Set the aspect project as the startup project, then use F5 as usually.
Last edited by gfraiteur on Sat Jun 14, 2008 8:03 pm, edited 1 time in total.
Reason: Mistake correction
Reason: Mistake correction
Gael Fraiteur, project leader
- gfraiteur
- Site Admin
- Posts: 834
- Joined: Tue Dec 18, 2007 3:09 pm
- First Name: Gael
- Last Name: Fraiteur
- Company: postsharp.org
Re: Debugging aspects at compile-time using VS 2008
Hi Gael,
I did as you suggested: created a class library for my aspects and tried to debug it using msbuild as external program; it didn't work
Passing the dll as argument to msbuild yields error "Data at the root level is invalid. Line 1, position 1."; I am no msbuild expert, but I can recognize an XmlException
and that's exactly what I got here, as msbuild expects a well-formed XML as input which should be my .csproj, not the assembly, right?
I made some investigations and found another way, although way too complicated: using postsharp.exe as external program, with the same arguments as the ones received usually by Exec task (that huge long command line, I copied it from msbuild's output) Worked like a charm, no more popups but I don't feel comfortable with all arguments "hard-coded"...so I stick to the external tool for now.
I did as you suggested: created a class library for my aspects and tried to debug it using msbuild as external program; it didn't work
I made some investigations and found another way, although way too complicated: using postsharp.exe as external program, with the same arguments as the ones received usually by Exec task (that huge long command line, I copied it from msbuild's output) Worked like a charm, no more popups but I don't feel comfortable with all arguments "hard-coded"...so I stick to the external tool for now.
- morphine
- Posts: 6
- Joined: Sat Jun 07, 2008 10:16 am
- First Name: Dan
- Last Name: M.
Re: Debugging aspects at compile-time using VS 2008
Sure, you had to pass the csproj to msbuild, not the dll. My mistake. I will edit my previous post.
Gael Fraiteur, project leader
- gfraiteur
- Site Admin
- Posts: 834
- Joined: Tue Dec 18, 2007 3:09 pm
- First Name: Gael
- Last Name: Fraiteur
- Company: postsharp.org
Re: Debugging aspects at compile-time using VS 2008
Hi,
This doesn't work, I get these exceptions on build:
Unhandled exception: PostSharp.CodeModel.BindingException: Error while loading the assembly "obj\Debug\Before-PostSharp\MyAspects.dll": Absolute path information is required.
===== PostSharp Assembly Binder =================
Loading assembly from file {obj\Debug\Before-PostSharp\MyAspects.dll}.
System.ArgumentException: Absolute path information is required.
The post build event is:
Suppose it builds: the command should not do more than displaying messages in VS's output window rather in system's console; since I want to be able to debug the thing, I should add /p=PostSharpAttachDebugger=true, right? I did this and got VS JIT popup, only that this time it only displays "New instance of VS", which I cannot use.
Even worse: clicking No on the popup window seems to run the post build event again without closing the msbuild process, so I ended up having plenty of msbuild.exe processes in task manager; the only way to shut them down was to end process tree.
This doesn't work, I get these exceptions on build:
Unhandled exception: PostSharp.CodeModel.BindingException: Error while loading the assembly "obj\Debug\Before-PostSharp\MyAspects.dll": Absolute path information is required.
===== PostSharp Assembly Binder =================
Loading assembly from file {obj\Debug\Before-PostSharp\MyAspects.dll}.
System.ArgumentException: Absolute path information is required.
The post build event is:
- Code: Select all
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe "$(ProjectPath)" /t:Rebuild /p:PostSharpUseCommandLine=false
Suppose it builds: the command should not do more than displaying messages in VS's output window rather in system's console; since I want to be able to debug the thing, I should add /p=PostSharpAttachDebugger=true, right? I did this and got VS JIT popup, only that this time it only displays "New instance of VS", which I cannot use.
Even worse: clicking No on the popup window seems to run the post build event again without closing the msbuild process, so I ended up having plenty of msbuild.exe processes in task manager; the only way to shut them down was to end process tree.
- morphine
- Posts: 6
- Joined: Sat Jun 07, 2008 10:16 am
- First Name: Dan
- Last Name: M.
5 posts • Page 1 of 1
