I have just upgraded a net451
classic dotnet project to multi-target project using net461/netstandard2.0
with reasonable success.
Did however come across this compiler error for net461
when it comes to gaining access legacy configuration files via:
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
This appears to not be a thing in netstandard2.0
:) Anyone know of any work arounds or good solutions?
Add the ConfigurationManager as a NuGet
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
</ItemGroup>
Use ConfigurationManager in C#
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Log4NetLogger.Configure(configFile.FilePath);
According to this article, which I found when looking for replacement for PlatformServices.Default.Application.ApplicationBasePath
, it should be either of:
AppDomain.CurrentDomain.SetupInformation.ApplicationName
Assembly.GetEntryAssembly().GetName().Name
Just like you, I've just found out that the first one does not exist in recent 2.0 so I'll be using the GetEntryAssembly
name..
..however keep in mind that GetEntryAssembly
may be null
when used i.e. from within a test runner like xUnit, or probably will be wrong if your appcode is ran from another not-yours hosting/startup module, etc - so that is not a perfect replacement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With