Skip to content

Commit d36787a

Browse files
author
Haroon Khan
committed
Another prototype project for Visual Studio Automation
1 parent c7e3257 commit d36787a

File tree

13 files changed

+838
-0
lines changed

13 files changed

+838
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Sln2NMake.VisualStudioAutomation.Interfaces;
6+
7+
namespace Sln2NMake.VisualStudio2010Automation
8+
{
9+
public class DTE : IDTE
10+
{
11+
internal DTE(EnvDTE.DTE dte)
12+
{
13+
_dte = dte;
14+
}
15+
16+
public ISolution Solution
17+
{
18+
get
19+
{
20+
return new Solution(_dte.Solution);
21+
}
22+
}
23+
24+
public void Quit()
25+
{
26+
_dte.Quit();
27+
}
28+
29+
private EnvDTE.DTE _dte;
30+
31+
#region IDTE Members
32+
33+
34+
public string Version
35+
{
36+
get { return _dte.Version; }
37+
}
38+
39+
#endregion
40+
}
41+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using EnvDTE;
3+
using MessageFilterImpl;
4+
using Sln2NMake.VisualStudioAutomation.Interfaces;
5+
using System.ComponentModel.Composition;
6+
7+
namespace Sln2NMake.VisualStudio2010Automation
8+
{
9+
[Export(typeof(IDTEFactory))]
10+
public class DTEFactory : IDTEFactory
11+
{
12+
private static string VISUAL_STUDIO_2010_PROGID="VisualStudio.DTE.10.0";
13+
14+
public static DTE InternalCreateDTE()
15+
{
16+
var dteType = System.Type.GetTypeFromProgID(VISUAL_STUDIO_2010_PROGID);
17+
var dteComObject = Activator.CreateInstance(dteType);
18+
var dte = dteComObject as EnvDTE.DTE;
19+
return new DTE(dte);
20+
}
21+
22+
public IDTE CreateDTE()
23+
{
24+
return DTEFactory.InternalCreateDTE();
25+
}
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace Sln2NMake.VisualStudio2010Automation
7+
{
8+
public interface IProjectMetaInfoView
9+
{
10+
string Kind { get; }
11+
string Version{get;}
12+
}
13+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Sln2NMake.VisualStudioAutomation.Interfaces;
6+
using System.ComponentModel.Composition.Hosting;
7+
using System.ComponentModel.Composition;
8+
using System.Reflection;
9+
10+
namespace Sln2NMake.VisualStudio2010Automation
11+
{
12+
public class ProjectItem : IProjectItem
13+
{
14+
15+
private CompositionContainer _container;
16+
17+
[ImportMany("CreateProject", typeof(Func<EnvDTE.Project, IProject>))]
18+
public IEnumerable<Lazy<Func<EnvDTE.Project, IProject>,IProjectMetaInfoView>> ProjectCreationFunctions { get; set; }
19+
20+
internal ProjectItem(EnvDTE.ProjectItem projectItem)
21+
{
22+
this._projectItem = projectItem;
23+
Compose();
24+
}
25+
26+
private void Compose()
27+
{
28+
var catalog = new AggregateCatalog();
29+
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
30+
_container = new CompositionContainer(catalog);
31+
_container.ComposeParts(this);
32+
33+
}
34+
35+
36+
public string Name
37+
{
38+
get
39+
{
40+
return _projectItem.Name;
41+
}
42+
}
43+
44+
public string Kind
45+
{
46+
get
47+
{
48+
return _projectItem.Kind;
49+
}
50+
}
51+
52+
public IEnumerable<IProjectItem> ProjectItems
53+
{
54+
get
55+
{
56+
if (_projectItem.ProjectItems == null)
57+
{
58+
yield break;
59+
}
60+
61+
foreach (var projectItemObject in _projectItem.ProjectItems)
62+
{
63+
yield return new ProjectItem(projectItemObject as EnvDTE.ProjectItem);
64+
}
65+
}
66+
}
67+
68+
public IProject SubProject
69+
{
70+
get
71+
{
72+
if (_projectItem.SubProject!=null)
73+
{
74+
// Find the appropriate Creation function and execute it.
75+
var lazyCreationFunction =
76+
ProjectCreationFunctions
77+
.SingleOrDefault(lazyCreator =>
78+
(lazyCreator.Metadata.Kind == _projectItem.SubProject.Kind &&
79+
lazyCreator.Metadata.Version == _projectItem.SubProject.DTE.Version)
80+
? true
81+
: false);
82+
if (lazyCreationFunction != null)
83+
{
84+
return lazyCreationFunction.Value(_projectItem.SubProject);
85+
}
86+
87+
return null;
88+
}
89+
return null;
90+
}
91+
}
92+
93+
94+
private EnvDTE.ProjectItem _projectItem;
95+
}
96+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Sln2NMake.VisualStudio2010Automation")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("Sln2NMake.VisualStudio2010Automation")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("8310ee85-4bbb-47c3-9ddd-6512af9db42d")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{743DFDD8-AD6A-4741-957A-015E51D6C32A}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Sln2NMake.VisualStudio2010Automation</RootNamespace>
12+
<AssemblyName>Sln2NMake.VisualStudio2010Automation</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
35+
<EmbedInteropTypes>True</EmbedInteropTypes>
36+
</Reference>
37+
<Reference Include="EnvDTE100, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
38+
<EmbedInteropTypes>True</EmbedInteropTypes>
39+
</Reference>
40+
<Reference Include="Microsoft.VisualStudio.VCProjectEngine, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
41+
<SpecificVersion>False</SpecificVersion>
42+
<EmbedInteropTypes>True</EmbedInteropTypes>
43+
<HintPath>..\..\..\..\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.VCProjectEngine.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System" />
46+
<Reference Include="System.ComponentModel.Composition" />
47+
<Reference Include="System.Core" />
48+
<Reference Include="System.Xml.Linq" />
49+
<Reference Include="System.Data.DataSetExtensions" />
50+
<Reference Include="Microsoft.CSharp" />
51+
<Reference Include="System.Data" />
52+
<Reference Include="System.Xml" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<Compile Include="DTE.cs" />
56+
<Compile Include="DTEFactory.cs" />
57+
<Compile Include="IProjectMetaInfoView.cs" />
58+
<Compile Include="VCCustomBuildRule.cs" />
59+
<Compile Include="VCFile.cs" />
60+
<Compile Include="VCFileConfiguration.cs" />
61+
<Compile Include="VCppProject.cs" />
62+
<Compile Include="ProjectItem.cs" />
63+
<Compile Include="Properties\AssemblyInfo.cs" />
64+
<Compile Include="Solution.cs" />
65+
<Compile Include="SolutionFolderProject.cs" />
66+
<Compile Include="VCRuntimeProperty.cs" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<ProjectReference Include="..\..\impromptu-Interface\ImpromptuInterface\ImpromptuInterface.csproj">
70+
<Project>{DAB7C056-660A-4153-8FF2-B80A41310AD7}</Project>
71+
<Name>ImpromptuInterface</Name>
72+
</ProjectReference>
73+
<ProjectReference Include="..\Sln2NMake.VisualStudioAutomation.Interfaces\Sln2NMake.VisualStudioAutomation.Interfaces.csproj">
74+
<Project>{712742EB-C9A8-4532-AA26-AAE6F0A90282}</Project>
75+
<Name>Sln2NMake.VisualStudioAutomation.Interfaces</Name>
76+
</ProjectReference>
77+
</ItemGroup>
78+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
79+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
80+
Other similar extension points exist, see Microsoft.Common.targets.
81+
<Target Name="BeforeBuild">
82+
</Target>
83+
<Target Name="AfterBuild">
84+
</Target>
85+
-->
86+
</Project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Sln2NMake.VisualStudioAutomation.Interfaces;
6+
using System.ComponentModel.Composition;
7+
using System.ComponentModel.Composition.Hosting;
8+
using System.Reflection;
9+
10+
namespace Sln2NMake.VisualStudio2010Automation
11+
{
12+
public class Solution : ISolution
13+
{
14+
private EnvDTE.Solution _solution;
15+
private CompositionContainer _container;
16+
17+
[ImportMany("CreateProject", typeof(Func<EnvDTE.Project, IProject>))]
18+
public IEnumerable<Lazy<Func<EnvDTE.Project, IProject>,IProjectMetaInfoView>> ProjectCreationFunctions { get; set; }
19+
20+
public Solution(EnvDTE.Solution solution)
21+
{
22+
this._solution = solution;
23+
// Compose the creation functions
24+
Compose();
25+
}
26+
27+
private void Compose()
28+
{
29+
var catalog = new AggregateCatalog();
30+
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
31+
_container = new CompositionContainer(catalog);
32+
_container.ComposeParts(this);
33+
}
34+
35+
public void Open(string solutionPath)
36+
{
37+
_solution.Open(solutionPath);
38+
}
39+
40+
public void Close()
41+
{
42+
_solution.Close();
43+
}
44+
45+
public IEnumerable<IProject> Projects
46+
{
47+
get
48+
{
49+
if (null ==_solution.Projects)
50+
{
51+
yield break;
52+
}
53+
foreach (var projectObject in _solution.Projects)
54+
{
55+
var projectComObject = projectObject as EnvDTE.Project;
56+
// Find the correct Creation method for the project we want
57+
var lazyCreationFunction =
58+
ProjectCreationFunctions.SingleOrDefault(lazyCreator =>
59+
(lazyCreator.Metadata.Kind == projectComObject.Kind &&
60+
lazyCreator.Metadata.Version == projectComObject.DTE.Version) ? true : false);
61+
if (lazyCreationFunction != null)
62+
{
63+
yield return lazyCreationFunction.Value(projectComObject);
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)