So I recently figured my .NET compiler is outdated, seeing as it can't use static imports (using static ...
), so I was here to ask, how do I update it?
I tried redownloading .NET, and looking up how to update, but neither of which were really helpful. So can someone explain the steps of updating?
Thanks!
Cheers!
Cheers!
Discussion (20)
You can get the latest .NET SDKs from here: dotnet.microsoft.com/download
Alternatively, you can install visual studio, which should also install the latest SDK.
I recommend using the command “dotnet build” (or run) as opposed to csc, as the dotnet project workflow makes managing dependencies easy (especially when used with Visual Studio).
I tried this (as I thought I've said in the post), but
csc.exe
inC:\Windows\Microsoft.NET\Framework\<version>\
won't update (as in, a new verson folder won't be added (not the actual file updating)).How can I get the new version folder, so I can add it to my PATH?
You don't use that compiler any longer unless you need legacy bugs supported. The new compiler based on Roslyn is much better. It's faster, creates much better code, and can support C# 9 features on .Net Framework where the feature doesn't require the Core CLR.
So, then how do I use the modern CLI tool(s) (as far as I know, just
dotnet
) to compile mytest.cs
s?First, use
dotnet new console
to initialize a project in the folder with you source code. Thendotnet run
to build and run your program.Can you explain what exactly this does?
I really don't understand, and I can't see why there isn't a
dotnet compile <file)s)>
.Thanks for your help.
Cheers.
Doing
dotnet new console
creates a new “console” project in the current directory.It creates two files - a
.csproj
and aProgram.cs
file. TheProgram.cs
file contains your code (you can add as many extra cs files as you want). The.csproj
file contains information that helps the compiler understand how to build (aka compile) your project. For example, what libraries to use, what framework to build it for, whether to ignore certain warnings etc. Theobj/
folder can be ignored.In that project directory, you can use the command
dotnet run
to run your project. Alternatively, you can dodotnet build
to compile it, and then you can manually click the exe in thebin
folder.It is worth installing visual studio, as it provides a nice interface to manage all this stuff.
The
dotnet
tool is a wrapper for several other tools such as the nuget package manager and msbuild build system.The first command,
dotnet new console
tells the tool to create a newcsproj
(aka C# Project) file in the current directory, named the same as the current directory. The project file is used by the Roslyn compiler to make decisions about how to compile and link the results.The second command,
dotnet run
checks the current directory for acsproj
file, and if there is exactly one of them, then the project is compiled using the new Roslyn compiler using theDebug
configuration andAnyCPU
processor target. Assuming the compiler was successful at compiling the code to a shared DLL, it then gets the output type from the project file (in this case a standardexe
) and then links the dll with a bootstrapper for the host OS and outputs the executable binary using the default linker profile for the target.The
csproj
file is vital to creating an executable file that you can actually run. Since Dotnet Core and .Net 5.0 are cross-platform, many more pieces of information must be fed to the compiler to create usable binary code.So, how do I actually use any of that shit?
Primarily;
What happens if I don't make/have a
csproj
file?Do I have to do anything with the file when it's generated?
Why the fuck is it always more complicated than just a language and the compiler/interpreter, why is all this bullshit here, when I just want to do something simple (similar concept applies to Java)?
I just generated whatever this bullshit is.
LIKE, WHAT EVEN THE FUCK DOES THAT MEAN!?!?
In the early days of .Net Framework, the target was always known: The output would be MSIL, would be executed in the CLR, and would run on Windows. Now, none of these things are a hard fact. The Dotnet tool chain, including the Roslyn compiler and .Net Native linker, is capable of spitting out a CPU specific binary with any combination of platform headers, garbage collectors or executable formats that you can think of.
So, 20 years ago, csc.exe was endowed with what is known as "opinions". These opinions assumed that the C# it was ingesting was going to run on the Microsoft built CLR (with complete access to all its resources) in Windows.
But times have changed. Microsoft is actively developing and supporting C# and F# running on WASM, Windows, Linux, MacOS, iOS, Android and Tiezen. It is actively developing and supporting code generators for x86, AMD64, ARM, ARM64 and WASM. This means that the compiler has to accept many choices to put together a strategy to go from
Hello World
to01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100
which makes being opinionated bad.To reign in the dizzying array of options , Microsoft introduced a new, simpler project file format with Dotnet Core that would allow the easy configuration of one or multiple build scenarios from a single file format. The default project file specifies the default SDK to use for base libraries, what output format (dll, exe, windows exe, WASM), and what version of ,Net the application will run under. By adding more properties you can further specialize the build of your application
Without the csproj file you would have to feed these options to the compiler on each build.
Why is it built to look like XML, though? Tgat shit is fucking confusing to understand, or remember.
It would have been btter if they made it look like, or be INI/JSON.
Can you send me a tutorial on how to use this?
The csproj file has actually been around as long as C# has, and it has always been an XML file. When they reworked the project file for Dotnet Core they actually did make it JSON at first, but they decided to stick with XML. I'm sure the fact that the project file is actually a valid MSBuild script had a lot to do with that decision. You can define MSBuild tasks and use them right in the csproj file to do things like move resources around before or after compiling code.
docs.microsoft.com/en-us/dotnet/co...
Uhhh, are you a bot? This is totally irrelevant.
Don’t interact with them, just report as spam and move on.
Where's the "report" button?
Three dots (top left of comment) -> report abuse.