Program.cs file
using System;
using Microsoft.Extensions.DependencyModel;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(DependencyContext.Default == null);
}
}
}
project.json file:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.Extensions.DependencyModel": "1.0.0-rc2-final"
},
"frameworks": {
"net451": {
}
}
}
run dotnet run --framework net451.
console output as False.
console output as True:
Project hwdotnet (.NETFramework,Version=v4.5.1) will be compiled because inputs were modified
Compiling hwdotnet for .NETFramework,Version=v4.5.1
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:03.1174645
True
dotnet --info output:
.NET Command Line Tools (1.0.0-preview1-002702)
Product Information:
Version: 1.0.0-preview1-002702
Commit Sha: 6cde21225e
Runtime Environment:
OS Name: ubuntu
OS Version: 14.04
OS Platform: Linux
RID: ubuntu.14.04-x64
mono:
Mono JIT compiler version 4.4.0 (Stable 4.4.0.148/fcf7a6d Thu Apr 28 14:51:58 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen
/cc @pakrym
'preserveCompilationContext' should be set to 'true' in 'buildOptions' to get 'DependencyContext' on full framework.
@tugberkugurlu I'm going to close the issue. If @pakrym's suggestion did not help please let us know and we'll reopen.
@pakrym, @piotrpMSFT works as expected after having _"preserveCompilationContext": true_ :+1:
@pakrym @davidfowl DependencyContext.Default always returns null when executing from a .csproj of the "old stack" even though everything builds correctly.
That's because it relies on a specific file existing in the output that the old tool chain does not produce
Most helpful comment
'preserveCompilationContext' should be set to 'true' in 'buildOptions' to get 'DependencyContext' on full framework.