Skip to content

Commit

Permalink
Release v2.3, Fixed MVC WebProject Support, Fixed path for files with…
Browse files Browse the repository at this point in the history
… folders and minor improvements
  • Loading branch information
thiagoloureiro committed Oct 27, 2018
1 parent 184c87d commit 65a36cf
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 65 deletions.
20 changes: 11 additions & 9 deletions Dapper.Crud.Tests/Dapper.Crud.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,30 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="1.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="xunit">
<Version>2.3.1</Version>
<Version>2.4.0</Version>
</PackageReference>
<PackageReference Include="xunit.abstractions">
<Version>2.0.1</Version>
<Version>2.0.3</Version>
</PackageReference>
<PackageReference Include="xunit.analyzers">
<Version>0.9.0</Version>
<Version>0.10.0</Version>
</PackageReference>
<PackageReference Include="xunit.assert">
<Version>2.3.1</Version>
<Version>2.4.0</Version>
</PackageReference>
<PackageReference Include="xunit.core">
<Version>2.3.1</Version>
<Version>2.4.0</Version>
</PackageReference>
<PackageReference Include="xunit.extensibility.core">
<Version>2.3.1</Version>
<Version>2.4.0</Version>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio">
<Version>2.3.1</Version>
<Version>2.4.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runners">
<Version>2.0.0</Version>
Expand Down
24 changes: 13 additions & 11 deletions Dapper.Crud.Tests/TestAssembly.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using Dapper.Crud.VSExtension.Helpers;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using Assert = Xunit.Assert;

namespace Dapper.Crud.Tests
{
public class AssemblyTest
{
[Fact]
public void TestGenerateInstance()
{
// Arrange
var path = Path.GetFullPath(@"..\..\..\Dapper.Crud.Model\");
var objText = File.ReadAllText(path + "User.cs");
//[Fact, Ignore]
//public void TestGenerateInstance()
//{
// // Arrange
// var path = Path.GetFullPath(@"..\..\..\Dapper.Crud.Model\");
// var objText = File.ReadAllText(path + "User.cs");

// Act
var instance = AssemblyHelper.ExecuteCode(objText, "Dapper.Crud.ModelExample", "User", false);
// // Act
// var instance = AssemblyHelper.ExecuteCode(objText, "Dapper.Crud.ModelExample", "User", false);

// Assert
Assert.True(instance != null);
}
// // Assert
// Assert.True(instance != null);
//}
}
}
31 changes: 21 additions & 10 deletions Dapper.Crud.VSExtension/Dapper.Crud.VSExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,23 @@
<Content Include="stylesheet.css" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IdeaTech.System.Web.Mvc.Extensions">
<Version>1.0.5</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.Web.Optimization">
<Version>1.1.3</Version>
</PackageReference>
<PackageReference Include="Microsoft.Net.Compilers">
<Version>2.8.2</Version>
<Version>2.9.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.CoreUtility" Version="15.6.27740" />
<PackageReference Include="Microsoft.VisualStudio.Imaging" Version="15.7.27703" />
<PackageReference Include="Microsoft.VisualStudio.CoreUtility" Version="15.8.525" />
<PackageReference Include="Microsoft.VisualStudio.Imaging" Version="15.8.28010" />
<PackageReference Include="Microsoft.VisualStudio.OLE.Interop" Version="7.10.6071" />
<PackageReference Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.17" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="15.7.27703" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Framework" Version="15.7.27703" />
<PackageReference Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.27" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="15.8.28010" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Framework" Version="15.8.28010" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop" Version="7.10.6072" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.10.0" Version="10.0.30320" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.11.0" Version="11.0.61031" />
Expand All @@ -310,10 +318,13 @@
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.9.0" Version="9.0.30730" />
<PackageReference Include="Microsoft.VisualStudio.TextManager.Interop" Version="7.10.6071" />
<PackageReference Include="Microsoft.VisualStudio.TextManager.Interop.8.0" Version="8.0.50728" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="15.7.18" />
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="15.7.27703" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="15.3.53" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="15.7.109" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="15.8.168" />
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="15.8.28010" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="15.3.58" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="15.8.3252">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
82 changes: 51 additions & 31 deletions Dapper.Crud.VSExtension/Helpers/AssemblyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.CodeDom.Compiler;
using System.Linq;
using System.Reflection;
using System.Text;

Expand All @@ -9,51 +10,60 @@ public static class AssemblyHelper
{
private static Assembly BuildAssembly(string code)
{
var compiler = new Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider();
//Clean up
Environment.SetEnvironmentVariable("ROSLYN_COMPILER_LOCATION", null, EnvironmentVariableTarget.Process);

var compilerparams = new CompilerParameters
using (var compiler = new Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider())
{
GenerateExecutable = false,
GenerateInMemory = true
};
//Clean up
Environment.SetEnvironmentVariable("ROSLYN_COMPILER_LOCATION", null, EnvironmentVariableTarget.Process);

compilerparams.ReferencedAssemblies.Add("System.dll");
compilerparams.ReferencedAssemblies.Add("System.Core.dll");
compilerparams.ReferencedAssemblies.Add("System.Data.dll");
compilerparams.ReferencedAssemblies.Add("System.Data.Linq.dll");
compilerparams.ReferencedAssemblies.Add("System.Data.DataSetExtensions.dll");
compilerparams.ReferencedAssemblies.Add("System.Xml.dll");
compilerparams.ReferencedAssemblies.Add("System.Xml.Linq.dll");
compilerparams.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
compilerparams.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll");
compilerparams.ReferencedAssemblies.Add("System.Web.dll");
compilerparams.ReferencedAssemblies.Add("System.Web.Abstractions.dll");
var compilerparams = new CompilerParameters
{
GenerateExecutable = false,
GenerateInMemory = true
};

CompilerResults results =
compiler.CompileAssemblyFromSource(compilerparams, code);
if (results.Errors.HasErrors)
{
StringBuilder errors = new StringBuilder("Compiler Errors :\r\n");
foreach (CompilerError error in results.Errors)
compilerparams.ReferencedAssemblies.Add("System.dll");
compilerparams.ReferencedAssemblies.Add("System.Core.dll");
compilerparams.ReferencedAssemblies.Add("System.Data.dll");
compilerparams.ReferencedAssemblies.Add("System.Data.Linq.dll");
compilerparams.ReferencedAssemblies.Add("System.Data.DataSetExtensions.dll");
compilerparams.ReferencedAssemblies.Add("System.Xml.dll");
compilerparams.ReferencedAssemblies.Add("System.Xml.Linq.dll");
compilerparams.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
compilerparams.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll");
compilerparams.ReferencedAssemblies.Add("System.Web.dll");
compilerparams.ReferencedAssemblies.Add("System.Web.Abstractions.dll");
compilerparams.ReferencedAssemblies.Add("System.Web.Mvc.dll");
compilerparams.ReferencedAssemblies.Add("System.Web.Optimization.dll");

CompilerResults results =
compiler.CompileAssemblyFromSource(compilerparams, code);
if (results.Errors.HasErrors)
{
errors.Append($"Line {error.Line},{error.Column}\t: {error.ErrorText}\n");
StringBuilder errors = new StringBuilder("Compiler Errors :\r\n");
foreach (CompilerError error in results.Errors)
{
errors.Append($"Line {error.Line},{error.Column}\t: {error.ErrorText}\n");
}

compiler.Dispose();

throw new Exception(errors.ToString());
}
else
{
return results.CompiledAssembly;
}
throw new Exception(errors.ToString());
}
else
{
return results.CompiledAssembly;
}
}

public static object ExecuteCode(string code, string namespacename, string classname, bool isstatic)
{
Assembly asm = BuildAssembly(code);
classname = FixClassName(classname);

object instance = null;
Type type = null;

if (isstatic)
{
type = asm.GetType(namespacename + "." + classname);
Expand All @@ -65,5 +75,15 @@ public static object ExecuteCode(string code, string namespacename, string class
}
return instance;
}

private static string FixClassName(string classname)
{
if (classname.Contains("\\"))
{
var str = classname.Split('\\');
classname = str.Last(); // last item of the array
}
return classname;
}
}
}
4 changes: 2 additions & 2 deletions Dapper.Crud.VSExtension/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// 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("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
2 changes: 1 addition & 1 deletion Dapper.Crud.VSExtension/frmExtension.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Dapper.Crud.VSExtension/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="d7261d0b-5f95-456b-9b6a-b127d9afc8e4" Version="2.2" Language="en-US" Publisher="Thiago Loureiro" />
<Identity Id="d7261d0b-5f95-456b-9b6a-b127d9afc8e4" Version="2.3" Language="en-US" Publisher="Thiago Loureiro" />
<DisplayName>Dapper Crud Generator</DisplayName>
<Description xml:space="preserve">Generate CRUD easily with Dapper from your existing Models</Description>
<MoreInfo>https://github.com/thiagoloureiro/Dapper.Crud.Extension</MoreInfo>
Expand Down

0 comments on commit 65a36cf

Please sign in to comment.