Skip to content

Commit

Permalink
Initial work
Browse files Browse the repository at this point in the history
Now getting an error resolving a method in the Roslyn DLLs when the
template runs in a test VS environment.
  • Loading branch information
Kal Ahmed committed Jun 29, 2015
1 parent 64e3534 commit 2c27bc7
Show file tree
Hide file tree
Showing 20 changed files with 1,225 additions and 490 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>14.0</OldToolsVersion>
<UpgradeBackupLocation />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{947BB231-EC4F-45AD-90BF-44121DBD3FE7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BrightstarCodegenEntityContext</RootNamespace>
<AssemblyName>BrightstarCodegenEntityContext</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<GeneratePkgDefFile>false</GeneratePkgDefFile>
<IncludeAssemblyInVSIXContainer>false</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CreateVsixContainer>false</CreateVsixContainer>
<DeployExtension>false</DeployExtension>
<DeployVSTemplates>false</DeployVSTemplates>
<CopyVsixManifestToOutput>false</CopyVsixManifestToOutput>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.CoreUtility">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="BrightstarCodegenEntityContext.ico" />
</ItemGroup>
<ItemGroup>
<VSTemplate Include="BrightstarCodegenEntityContext.vstemplate">
<SubType>Designer</SubType>
</VSTemplate>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="EntityContext.tt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Binary file not shown.
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
<TemplateData>
<Name>Brightstar Codegen Entity Context</Name>
<Description>A project item for generating a strongly-typed EntityContext class and BrightstarDB persistence-aware classes using the BrightstarDB Roslyn code generator.</Description>
<Icon>BrightstarCodegenEntityContext.ico</Icon>
<TemplateID>289eae03-0382-4b26-9f72-42361074eadf</TemplateID>
<ProjectType>CSharp</ProjectType>
<RequiredFrameworkVersion>4.0</RequiredFrameworkVersion>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<DefaultName>EntityContext.tt</DefaultName>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true">EntityContext.tt</ProjectItem>
</TemplateContent>
<WizardExtension>
<Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>
<WizardData>
<packages repository="extension"
repositoryId="EntityFrameworkCodegen.BrightstarDB.66d16fc6-15f8-465f-8ddf-c7ff7373afce">
<package id="BrightstarDB.CodeGeneration.T4" version="1.11.0"/>
<package id="BrightstarDBLibs" version="1.11.0" />
</packages>
</WizardData>
</VSTemplate>
@@ -0,0 +1,143 @@
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ CleanupBehavior processor="T4VSHost" CleanupAfterProcessingtemplate="true" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="EnvDTE" #>
<#
// set this to either "CSharp" or "VisualBasic"
var language = "CSharp";

// you can move the .tt file to a different folder in your project to have the entity context's namespace change accordingly
// or, you could just set it manually here
var contextNamespace = this.Host.ResolveParameterValue("directiveId", "namespaceDirectiveProcessor", "namespaceHint") ?? "Default.Namespace";

var solutionPath = this.DTE.Solution.FileName;

this.SetFileExtensionForLanguage(language);
this.HookAssemblyResolution();
var generator = Type.GetType("BrightstarDB.CodeGeneration.Generator, BrightstarDB.CodeGeneration");
var generateMethod = generator.GetMethod("Generate");
var result = (string)generateMethod.Invoke(null, new[] { language, solutionPath, contextNamespace, "EntityContext", null, null, null });

this.WriteLine(result);
#>
<#+
private DTE dte;

private DTE DTE
{
get
{
if (this.dte == null)
{
var hostServiceProvider = (IServiceProvider)this.Host;
this.dte = (DTE)hostServiceProvider.GetService(typeof(DTE));
}

return this.dte;
}
}

private void SetFileExtensionForLanguage(string language)
{
switch (language)
{
case "CSharp":
this.Host.SetFileExtension(".g.cs");
break;
case "VisualBasic":
this.Host.SetFileExtension(".g.vb");
break;
default:
this.Host.SetFileExtension(".g");
break;
}
}

private void HookAssemblyResolution()
{
var templateDirectory = Path.GetDirectoryName(this.Host.TemplateFile);
var currentDirectory = templateDirectory;
string packagesDirectory = null;

while (Path.GetPathRoot(currentDirectory) != currentDirectory)
{
var packagesDirectories = Directory.GetDirectories(currentDirectory, "packages");

if (packagesDirectories.Length == 0)
{
currentDirectory = Path.GetDirectoryName(currentDirectory);
continue;
}
else if (packagesDirectories.Length > 1)
{
throw new InvalidOperationException("More than one packages directory detected - aborting.");
}
else
{
packagesDirectory = packagesDirectories[0];
break;
}
}

if (packagesDirectory == null)
{
throw new InvalidOperationException("Could not find packages directory relative to the template's directory (" + templateDirectory + ").");
}

this.Debug("packages directory: {0}", packagesDirectory);

var packageDirectories = Directory.GetDirectories(packagesDirectory, "BrightstarDB.CodeGeneration.T4.*");

if (packageDirectories.Length == 0)
{
throw new InvalidOperationException("Could not find BrightstarDB.CodeGeneration.T4 package in packages directory (" + packagesDirectory + ").");
}
else if (packageDirectories.Length > 1)
{
throw new InvalidOperationException("More than 1 version of the BrightstarDB.CodeGeneration.T4 package was found in the packages directory (" + packagesDirectory + "). You must choose 1 version and remove the others.");
}

var packageDirectory = packageDirectories.First();
this.Debug("package directory: {0}", packageDirectory);

var assembliesDirectory = Path.Combine(packageDirectory, "tools");
this.Debug("assemblies directory: {0}", assembliesDirectory);

if (!Directory.Exists(assembliesDirectory))
{
throw new InvalidOperationException("Package directory " + packageDirectory + " was found but no 'tools' subdirectory was found within.");
}

AppDomain.CurrentDomain.AssemblyResolve += (s, e) =>
{
this.Debug("resolve: {0}", e.Name);

var matches = Directory.GetFiles(assembliesDirectory, e.Name + ".dll", SearchOption.TopDirectoryOnly);

if (matches.Length == 0)
{
this.Debug("Failed to find assembly in assemblies directory ({0}) named '{1}'.", assembliesDirectory, e.Name);
return null;
}
else if (matches.Length > 1)
{
this.Debug("Found more than one potential match for '{0}' in assemblies directory ({0}). Bailing.", e.Name, assembliesDirectory);
return null;
}

var match = matches.First();
this.Debug("match: {0}", match);

return Assembly.LoadFrom(match);
};
}

private void Debug(string format, params object[] args)
{
//this.WriteLine("// " + string.Format(format, args));
}
#>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BrightstarCodegenEntityContext")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Kal Ahmed")]
[assembly: AssemblyProduct("BrightstarCodegenEntityContext")]
[assembly: AssemblyCopyright("Copyright © Kal Ahmed 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("947bb231-ec4f-45ad-90bf-44121dbd3fe7")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 2c27bc7

Please sign in to comment.