After checking the environment on my win10 laptop, I found there was a TargetFramework variable set there. After removing it, it works as expected now.
I close this question now.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I`m currently learning how to create multi-targeting library with dotnet.
I created a multi-targeting library in .net6 and .net 7. However, when I calling the method in this library, the output doesn`t work as my expectation.
excution command:
in powershell, enter the root folder, and excute
dotnet run --project .\src\InvokeTestCon\
expected output:
Hello from NET7_0
Main called in NET7_0
actual output:
Hello from other
Main called in NET7_0
code snippet:
# program.cs
Console.WriteLine(Tools.GetName());
#if NET7_0
Console.WriteLine("Main called in NET7_0");
#endif
# Tools.cs
public static class Tools
{
public static string GetName()
{
#if NET7_0
return "Hello from NET7_0";
#else
return "Hello from other";
#endif
}
}
dev environment:
win10 64bit, with .net6.0.405 sdk and .net7.0.102 sdk installed.
I have also uploaded my test code in github. Is there anyone with multi-targeting library experience could help me out?
https://github.com/ali50m/InvokeTest
Thanks!
After checking the environment on my win10 laptop, I found there was a TargetFramework variable set there. After removing it, it works as expected now.
I close this question now.