Skip to content

Commit 7f66cb2

Browse files
committed
Automated setting of TargetFrameworkVersion
1 parent 77ce118 commit 7f66cb2

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

EntityFramework.Reverse.POCO.Generator/Database NorthwindSqlCe40.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// ReSharper disable RedundantNameQualifier
2121
// ReSharper disable RedundantOverridenMember
2222
// ReSharper disable UseNameofExpression
23-
// TargetFrameworkVersion = 4.51
23+
// TargetFrameworkVersion = 4.5
2424
#pragma warning disable 1591 // Ignore "Missing XML Comment" warning
2525

2626

EntityFramework.Reverse.POCO.Generator/Database NorthwindSqlCe40.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
DbContextInterfaceBaseClasses = "System.IDisposable"; // Specify what the base classes are for your database context interface
1919
DbContextBaseClass = "System.Data.Entity.DbContext"; // Specify what the base class is for your DbContext. For ASP.NET Identity use "IdentityDbContext<ApplicationUser>"
2020
//DefaultConstructorArgument = "EnvironmentConnectionStrings.MyDbContext"; //defaults to "Name=" + ConnectionStringName
21-
TargetFrameworkVersion = "4.51"; // Please set this to your .NET framework version, 4.0, 4.5, 4.51, etc.
2221
ConfigurationClassName = "Configuration"; // Configuration, Mapping, Map, etc. This is appended to the Poco class name to configure the mappings.
2322
ConfigFilenameSearchOrder = new[] { "app.config", "web.config", "app.config.transform", "web.config.transform" }; // Add more here if required. The config files are searched for in the local project first, then the whole solution second.
2423
MakeClassesPartial = false;

EntityFramework.Reverse.POCO.Generator/Database.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// ReSharper disable RedundantNameQualifier
2424
// ReSharper disable RedundantOverridenMember
2525
// ReSharper disable UseNameofExpression
26-
// TargetFrameworkVersion = 4.51
26+
// TargetFrameworkVersion = 4.5
2727
#pragma warning disable 1591 // Ignore "Missing XML Comment" warning
2828

2929

EntityFramework.Reverse.POCO.Generator/Database.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
DbContextInterfaceBaseClasses = "System.IDisposable"; // Specify what the base classes are for your database context interface
1919
DbContextBaseClass = "System.Data.Entity.DbContext"; // Specify what the base class is for your DbContext. For ASP.NET Identity use "IdentityDbContext<ApplicationUser>"
2020
//DefaultConstructorArgument = "EnvironmentConnectionStrings.MyDbContext"; //defaults to "Name=" + ConnectionStringName
21-
TargetFrameworkVersion = "4.51"; // Please set this to your .NET framework version, 4.0, 4.5, 4.51, etc.
2221
ConfigurationClassName = "Configuration"; // Configuration, Mapping, Map, etc. This is appended to the Poco class name to configure the mappings.
2322
ConfigFilenameSearchOrder = new[] { "app.config", "web.config", "app.config.transform", "web.config.transform" }; // Add more here if required. The config files are searched for in the local project first, then the whole solution second.
2423
MakeClassesPartial = false;

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.Core.ttinclude

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,12 @@
115115
string PocoNamespace, ContextNamespace, UnitOfWorkNamespace, PocoConfigurationNamespace = "";
116116

117117
// Settings to allow TargetFramework checks
118-
private static string TargetFrameworkVersion;
118+
private static float _targetFrameworkVersion;
119119
Func<string,bool> IsSupportedFrameworkVersion = (string frameworkVersion) =>
120120
{
121-
if (!string.IsNullOrEmpty(TargetFrameworkVersion))
122-
{
123-
var nfi = CultureInfo.InvariantCulture.NumberFormat;
124-
float target = float.Parse(TargetFrameworkVersion, nfi);
125-
float isSupported = float.Parse(frameworkVersion, nfi);
126-
return isSupported <= target;
127-
}
128-
return true;
121+
var nfi = CultureInfo.InvariantCulture.NumberFormat;
122+
var isSupported = float.Parse(frameworkVersion, nfi);
123+
return isSupported <= _targetFrameworkVersion;
129124
};
130125

131126

@@ -312,7 +307,7 @@
312307

313308
private void InitConnectionString()
314309
{
315-
if(!String.IsNullOrEmpty(_connectionString))
310+
if(!string.IsNullOrEmpty(_connectionString))
316311
return;
317312

318313
_connectionString = GetConnectionString(ref ConnectionStringName, out _providerName, out _configFilePath);
@@ -519,6 +514,14 @@
519514

520515
private DbProviderFactory GetDbProviderFactory()
521516
{
517+
if (_targetFrameworkVersion < 1.0f)
518+
{
519+
var project = GetCurrentProject();
520+
var targetFrameworkMoniker = project.Properties.Item("TargetFrameworkMoniker").Value.ToString();
521+
var targetFramework = new System.Runtime.Versioning.FrameworkName(targetFrameworkMoniker).Version;
522+
_targetFrameworkVersion = targetFramework.Major + (targetFramework.Minor * 0.1f);
523+
}
524+
522525
InitConnectionString();
523526

524527
WriteLine("// ------------------------------------------------------------------------------------------------");

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.ttinclude

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fileManager.StartHeader();
1414
// ReSharper disable RedundantNameQualifier
1515
// ReSharper disable RedundantOverridenMember
1616
// ReSharper disable UseNameofExpression
17-
// TargetFrameworkVersion = <#=TargetFrameworkVersion #>
17+
// TargetFrameworkVersion = <#= _targetFrameworkVersion #>
1818
#pragma warning disable 1591 // Ignore "Missing XML Comment" warning
1919

2020
<#if (ElementsToGenerate.HasFlag(Elements.Poco))

0 commit comments

Comments
 (0)