.NET Standard pre-processor switch and ConfigFileHelper

Posts   
 
    
Posts: 27
Joined: 02-Oct-2008
# Posted on: 27-Aug-2019 02:19:21   

Using 5.6, decided to start a project on Net Core...with the adapter templates.

I think there are two things that I don't understand.

  1. The pre-processor directive in DataAccessAdapter for NETSTANDARD2_0 doesn't seem to be working for me (on VS2017 or VS2019). The project that I generated is set to .NET Core 2.0 but is choosing to compile the ConfigFileHelper line, which fails because ReadConnectionStringFromConfig does not exist in the .NET Standard 2.0 ORMSupportClasses. The ConfigFileHelper class exists but is empty (which I assume is fine because if the directive were working for me it would not be using the ConfigFileHelper class anyway.)

I solved this by removing this code and only leaving the RuntimeConfiguration line and then hooked it up in the Startup.cs of the project that consumes the data project.

private static string ReadConnectionStringFromConfig()
{
//#if NETSTANDARD2_0
            return RuntimeConfiguration.GetConnectionString(ConnectionStringKeyName);
//#else
//         return ConfigFileHelper.ReadConnectionStringFromConfig(ConnectionStringKeyName);
//#endif
}

And in Startup.cs

RuntimeConfiguration.AddConnectionString("ConnectionString.SQL Server (SqlClient)", "connection string");

// Configure the DQE
RuntimeConfiguration.ConfigureDQE<SQLServerDQEConfiguration>(
c => c.SetTraceLevel(TraceLevel.Verbose)
.AddDbProviderFactory(typeof(System.Data.SqlClient.SqlClientFactory))
.SetDefaultCompatibilityLevel(SqlServerCompatibilityLevel.SqlServer2012));

This all works fine but of course when I regen the code, I have to go back in and modify the ReadConnectionStringFromConfig method.

Curious if there are other steps, such as a VS setting, to get the pre-processor directive to work?

  1. I assume that I can have the consuming project set to a higher version of .NET Core (2.2 in this case) than the LLBLGen project (which is set to 2.0). I'm assuming so since it compiles and works fine with the changes I made above.

Thanks! Timothy

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Aug-2019 09:11:35   

Hi Timothy,

In your generated project files (csproj) you have to set the target framework as .NET Standard 2.0 not netcore. (this should be the default when the files are generated) and the projects are then usable by any other project that targets a platform that's compatible with netstandard2.0 (and .net core 2.2 is compatible with netstandard2.0)

David Elizondo | LLBLGen Support Team
Posts: 27
Joined: 02-Oct-2008
# Posted on: 27-Aug-2019 19:27:39   

Ok, thanks a lot.

I regenerated the project as .NET Standard 2.0 using VS 2019 and it worked fine, i.e. the pre-processor switch works now.

Appreciate you pointing me in the right direction.

I understood that .NET Standard is essentially a set of functionality covered in a specific .Net framework implementation but it didn't sink in that it was also a project target.

https://docs.microsoft.com/en-us/dotnet/standard/net-standard#net-implementation-support