Replies: 9 comments
-
I'm not sure how would the compiler find the version, especially considering other target frameworks, like .Net Standard and .Net Core, exist. Looking at version attributes in various versions of the System.dll reference assembly, I see: .Net Framework 4.7: [assembly: AssemblyFileVersion("4.7.2046.0")]
[assembly: AssemblyInformationalVersion("4.7.2046.0")]
[assembly: AssemblyVersion("4.0.0.0")] .Net Framework 4.7.1: [assembly: AssemblyFileVersion("4.7.2558.0")]
[assembly: AssemblyInformationalVersion("4.7.2558.0")]
[assembly: AssemblyVersion("4.0.0.0")] .Net Standard 2.0: [assembly: AssemblyFileVersion("4.6.25714.01")]
[assembly: AssemblyInformationalVersion("4.6.25714.01 built by: dlab-DDVSOWINAGE032. Commit Hash: b7f182415927d3b98445d043e1680c56b9d1f17c")]
[assembly: AssemblyVersion("4.0.0.0")] .Net Core 2.0: [assembly: AssemblyFileVersion("4.6.25519.3")]
[assembly: AssemblyInformationalVersion("4.6.25519.3")]
[assembly: AssemblyVersion("4.0.0.0")] Given this information, how is the compiler supposed to evaluate |
Beta Was this translation helpful? Give feedback.
-
I feel like most of this is better suited for the SDK and/or MSBuild. Essentially all of the metadata to create these defines should exist in the set of MSBuild properties (or could be defined there if they do not exist). A simple opt-in switch could be given so that such definitions are created and passed through to the compiler. |
Beta Was this translation helpful? Give feedback.
-
The SDK already has definitions for these, but the problem is that right now you need to do things like:
It would be nice if we could simply do:
but again, that would be an SDK responsibility. The closest thing which would need actual language support would be if we did something like |
Beta Was this translation helpful? Give feedback.
-
That's an interesting idea. Perhaps the C# compiler could advertise named features which could be queried through such a directive: #if available(TUPLES) Of course that would only work with language features specifically and wouldn't help with CLR/BCL versions. But perhaps a similar approach could be taken where the directive could reference whether a type or method exists: #if available(System.ValueTuple<int, string>.Deconstruct(int, string)) Ignore specific syntax, just tossing spaghetti against the wall regarding the concept. |
Beta Was this translation helpful? Give feedback.
-
What would be the point? In what situation do you have to compile the same source file with different versions of the compiler and want to use different code for each version? |
Beta Was this translation helpful? Give feedback.
-
You're right, doesn't make much sense comparing the features of the compiler itself. |
Beta Was this translation helpful? Give feedback.
-
@svick In place where we need to support many difference dotnet platform. Most of the time many library need to compile to multiple version. And almost all of the time we need to hack the source code and inject For example I work with unity and amazon lambda. Both have constraint on very difference dotnet. One based on dotnet mono and another stuck with dotnet core 1.1 while many library now was written in dotnet core 2.0. And each platform of unity also have many overlapping platform in each library. When I need to modify it then When I inject my code into the source and want to make a pull request. Another people use another platform also do the same with their platform. It make the act of modified the library in unison harder I was thinking opposite of the use case of #if !available(System.ValueTuple<int, string>.Deconstruct(int, string))
public static (int,string) Deconstruct(int i,string s)
{
// return
}
#endif |
Beta Was this translation helpful? Give feedback.
-
@Thaina I was specifically talking about using |
Beta Was this translation helpful? Give feedback.
-
@svick Sorry I don't actually understand what you mean In my understanding both my original proposal and of @HaloFour about |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Instead of relying on
#define
I think it would be useful if we could place directive#if
on referenced assembly with version syntax like nugetSomething like this
Beta Was this translation helpful? Give feedback.
All reactions