1

I need to exclude some bugged projects from a very big solution to do an automated build with this script.

I tried to edit the build configuration to exclude those project, and i tried also to unload them from the solution, but i found out that the only way to get a successful build with my script is by removing those projects from the solution.

And i need to do it programmatically.

So i googled and i found this answer but now that particular library has been splitted in 4 parts:

  • EnvDTE
  • EnvDTE80
  • EnvDTE90
  • EnvDTE100

and I can't even figure out how to use the new DTE and there's no useful documentantion on msdn (as usual)

my code is

System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.11.0");
Object obj = System.Activator.CreateInstance(type, true);
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)obj;

dte.Solution.Open(SlnPath);

but it get stuck on the .Open for ever (i use EnvDTE80 because EnvDTE100 doesn't have .DTE2)

I also tried with

Type latestSolution = Type.GetTypeFromProgID("VisualStudio.DTE.11.0", true);
EnvDTE100.Solution4 sln = (EnvDTE100.Solution4)Activator.CreateInstance(latestSolution, true);
sln.Open(SlnPath);

but on the second line I get

Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE100.Solution4'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{CDA7305C-78B6-4D9D-90AD-93EBE71F9341}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

any advice? thanks all

Community
  • 1
  • 1
Doc
  • 5,078
  • 6
  • 52
  • 88
  • 1
    Instead of removing the projects from the solution, you could also create a new solution configuration and exclude the projects from this configuration (menu `Build -> Configuration Manager`). Might be easier than to remove them. – Markus Mar 11 '14 at 15:18
  • SLN-files are normally text files (XML). So a **bad** workaround would be to open it as file, parse it, delete the project and save it. – harry Mar 11 '14 at 15:19
  • @Markus it doesn't work, the .sln file does not change and my script keep to build all projects (build script -> http://stackoverflow.com/questions/22227804/build-visual-studio-solution-from-code/22228159#22228159) – Doc Mar 11 '14 at 15:22
  • @user1934574 - proj files are XML. sln files are a steaming pile of ..... not xml. – Jamiec Mar 11 '14 at 15:23
  • @user1934574 already tried, it mess up EVERYTHING :D – Doc Mar 11 '14 at 15:23
  • 1
    I think markus meant maintain another solution configuration with the projects you dont want built configured that way - not dynamically tring to create that config - having it in tfs – Jamiec Mar 11 '14 at 15:25
  • build configurations are not visible from BuildRequestData (afaik) – Doc Mar 11 '14 at 16:09
  • 1
    @Doc: Maybe I misunderstand anything, but as far as I understand your requirements, they are solvable with a mix of tf.exe, MSBuild and project configurations - and no coding or changing the solution at all. Just to understand: for which reasons did you choose to go the EnvDTE way? If you describe your requirements in your question in greater detail, maybe someone can come up with a different approach that solves the requirements and also fixes/bypasses the actual problem that was the reason for the question. – Markus Mar 11 '14 at 19:27
  • right, i edited the question :) – Doc Mar 11 '14 at 22:02

1 Answers1

3

look into this project: https://slntools.codeplex.com/

var sln = SolutionFile.FromFile(solutionFullPath);
var projList = sln.Projects;
var proj = sln.Projects.FindByFullName("ProjNameToRemove");
sln.Projects.Remove(proj);
sln.Save(); // or .SaveAs("NewName.sln");