Am I doing something wrong, or is there a way around this problem ?
using System.Runtime.InteropServices;using EnvDTE;using EnvDTE100;using EnvDTE80;namespace Codyflex.VisualStudioAutomation {publicclass VsTest {publicstaticvoid Test() { OleMessageFilter.Register(); // See: http://msdn.microsoft.com/en-us/library/ms228772.aspxtry { DTE2 dte2 = (DTE2) Marshal.GetActiveObject("VisualStudio.DTE.10.0"); Solution4 solution = (Solution4) dte2.Solution; Project project = solution.Item(@"TestTarget\TestTarget.csproj"); ProjectItem item = project.ProjectItems.Item("Class1.cs"); item.Delete(); // When run in debug mode, item.Delete() always throws// COMException "The item 'Class1.cs' cannot be deleted."//// Works OK if run without debugging. }finally { OleMessageFilter.Revoke(); } } } }
Regards
FrankG