Skip to content

Commit 912691e

Browse files
Prototype: Add initial support for project script generation, files, guid using EnvDTE model.
1 parent 2e7c183 commit 912691e

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

Diff for: ScriptEngine/ScriptEngine.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
<DebugSymbols>true</DebugSymbols>
4141
<DebugType>full</DebugType>
4242
<Optimize>false</Optimize>
43-
<OutputPath>bin\Debug\</OutputPath>
43+
<OutputPath>..\bin\</OutputPath>
4444
<DefineConstants>DEBUG;TRACE</DefineConstants>
4545
<ErrorReport>prompt</ErrorReport>
4646
<WarningLevel>4</WarningLevel>
4747
</PropertyGroup>
4848
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4949
<DebugType>pdbonly</DebugType>
5050
<Optimize>true</Optimize>
51-
<OutputPath>bin\Release\</OutputPath>
51+
<OutputPath>..\bin\</OutputPath>
5252
<DefineConstants>TRACE</DefineConstants>
5353
<ErrorReport>prompt</ErrorReport>
5454
<WarningLevel>4</WarningLevel>

Diff for: ScriptEngine/ScriptEnginePackage.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public sealed class ScriptEnginePackage : AsyncPackage
2626

2727
public dynamic vsModule;
2828
public DTE2 dte;
29+
public IVsSolution vsSolution;
2930

3031
/// <summary>
3132
/// Initialization of the package; this method is called right after the package is sited, so this is the place
@@ -38,7 +39,8 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
3839
{
3940
// Switch to main thread
4041
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
41-
dte = await this.GetServiceAsync(typeof(EnvDTE.DTE)) as DTE2;
42+
dte = await GetServiceAsync(typeof(EnvDTE.DTE)) as DTE2;
43+
vsSolution = await GetServiceAsync(typeof(IVsSolution)) as IVsSolution;
4244

4345
// Register menu handlers
4446
OleMenuCommandService commandService = await GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;

Diff for: Tools/vsDev/vsDev.cs

+50-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//css_ref \Prototyping\cppscriptcore\ScriptEngine\packages\Microsoft.VisualStudio.Shell.15.0.15.0.26228\lib\Microsoft.VisualStudio.Shell.15.0.dll
22
//css_ref C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\EnvDTE80.dll
3-
//css_ref \Prototyping\cppscriptcore\ScriptEngine\bin\Debug\ScriptEngine.dll
3+
//css_ref \Prototyping\cppscriptcore\bin\ScriptEngine.dll
44
//css_ref \Prototyping\cppscriptcore\ScriptEngine\packages\Microsoft.VisualStudio.Shell.Interop.7.10.6071\lib\Microsoft.VisualStudio.Shell.Interop.dll
55
//css_ref \Prototyping\cppscriptcore\ScriptEngine\packages\Microsoft.VisualStudio.OLE.Interop.7.10.6071\lib\Microsoft.VisualStudio.OLE.Interop.dll
66
//css_ref \Prototyping\cppscriptcore\ScriptEngine\packages\Microsoft.VisualStudio.Shell.Interop.8.0.8.0.50727\lib\Microsoft.VisualStudio.Shell.Interop.8.0.dll
@@ -10,10 +10,13 @@
1010
//css_ref \Prototyping\cppscriptcore\ScriptEngine\packages\Microsoft.VisualStudio.Shell.Framework.15.0.26228\lib\net45\Microsoft.VisualStudio.Shell.Framework.dll
1111
//css_ref C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\EnvDTE.dll
1212
//css_ref C:\Prototyping\cppscriptcore\bin\ScriptEngineStarter.exe
13+
//css_ref C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.VCProjectEngine.dll
1314
//css_include ..\VSModelSync\CodeBuilder.cs
1415
using EnvDTE;
1516
using EnvDTE80;
1617
using Microsoft.VisualStudio.Shell;
18+
using Microsoft.VisualStudio.Shell.Interop;
19+
using Microsoft.VisualStudio.VCProjectEngine;
1720
using ScriptEngine;
1821
using System;
1922
using System.Collections.Generic;
@@ -23,12 +26,14 @@
2326
using System.Reflection;
2427
using System.Text;
2528
using System.Threading.Tasks;
29+
using Constants = EnvDTE.Constants;
2630

2731
public class vsDev
2832
{
2933
public static bool Main( object arg )
3034
{
31-
Solution solution = ((ScriptEnginePackage)arg).dte.Solution;
35+
ScriptEnginePackage sepkg = (ScriptEnginePackage)arg;
36+
Solution solution = sepkg.dte.Solution;
3237

3338
ScriptHost.console.Clear();
3439
ScriptHost.console.WriteLine("Build: " + Assembly.GetExecutingAssembly().Location);
@@ -45,6 +50,8 @@ public static bool Main( object arg )
4550
// The "Miscellaneous Files" node is used to contain open files that are not associated
4651
// with the current project contents within the solution
4752
//
53+
// https://stackoverflow.com/questions/7160425/what-is-miscellaneous-files-inside-dte-vs2010-solution
54+
//
4855
if (project.Kind == Constants.vsProjectKindMisc)
4956
continue;
5057

@@ -62,19 +69,58 @@ public static bool Main( object arg )
6269
class Builder: SolutionProjectBuilder
6370
{
6471
static void Main(String[] args)
65-
{
66-
");
72+
{");
6773
code.Indent(2);
74+
75+
String name = project.Name;
76+
code.AppendLine("project(" + quoted(name) + ");");
77+
78+
Configuration[] configurations = project.ConfigurationManager.Cast<Configuration>().ToArray();
79+
code.AppendLine("configurations(" + String.Join(",", configurations.Select(x => quoted(x.ConfigurationName)).Distinct() ) + ");");
80+
81+
IVsHierarchy hierarchy;
82+
sepkg.vsSolution.GetProjectOfUniqueName(project.UniqueName, out hierarchy);
83+
Guid projectGuid;
84+
hierarchy.GetGuidProperty(Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid);
85+
86+
code.AppendLine("uuid(" + quoted(projectGuid.ToString()) + ");");
87+
88+
VCProject vcProject = project.Object as VCProject;
89+
VCFile[] files = ((IVCCollection)vcProject.Files).Cast<VCFile>().ToArray();
90+
String[] paths = files.Select(x => x.RelativePath).ToArray();
91+
92+
code.AppendLine("files(");
93+
code.Indent();
94+
for(int i = 0; i < paths.Length; i++)
95+
{
96+
code.Append(code.IndentString + quoted(paths[i]));
97+
98+
if ( i != paths.Length - 1)
99+
code.Append(",");
100+
101+
code.Append("\r\n");
102+
}
103+
code.UnIndent();
104+
code.AppendLine(");");
105+
68106
code.UnIndent();
69107
code.AppendLine("}");
70108
code.UnIndent();
71109
code.AppendLine("}");
72110

111+
ScriptHost.console.WriteLine("Saving " + script + "...");
73112
File.WriteAllText(script, code.ToString());
74113
}
75114
return false;
76115
}
77116

117+
118+
public static String quoted(String s)
119+
{
120+
return "\"" + s.Replace("\"", "\\\"") + "\"";
121+
}
122+
123+
78124
}
79125

80126

Diff for: Tools/vsDev/vsDev.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
<HintPath>..\..\ScriptEngine\packages\Microsoft.VisualStudio.Shell.Interop.9.0.9.0.30729\lib\Microsoft.VisualStudio.Shell.Interop.9.0.dll</HintPath>
8787
<Private>False</Private>
8888
</Reference>
89+
<Reference Include="Microsoft.VisualStudio.VCProjectEngine, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
90+
<SpecificVersion>False</SpecificVersion>
91+
<EmbedInteropTypes>True</EmbedInteropTypes>
92+
<HintPath>..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.VCProjectEngine.dll</HintPath>
93+
</Reference>
8994
<Reference Include="System" />
9095
<Reference Include="System.Core" />
9196
<Reference Include="Microsoft.CSharp" />

0 commit comments

Comments
 (0)