โ Running .NET Framework Project off of command line
I primarily work with .NET core, and it is a breeze with
dotnet
But I've recently come across a .NET Framework web project, and I wanted to know if it was possible to build and run it off the command line
Firstly I have managed to build it using msbuild
. and I know I can host using IIS, so in theory, I can write a simple batch file to:
1) Build the project
2) Copy the contents of the build to the web directory
3) Start the IIS site
But I wanted to know if there was a way to do this without going through this like I can with dotnet
for .NET Core20 Replies
The answer depends on what type of project format it's using.
.NET Framework projects can use SDK format, but they don't by default.
If it's in SDK format though, you should be able to use
dotnet
commands just fine.It does not use the SDK format, I'm sure of that, cause out of habit the first thing I tried was
dotnet build
I converted all of our projects at work running .NET Framework 4.8 to SDK format for similar reasons.
It's normally easy to convert, but given that it's an old web project, there might be some nuances I'm not aware of.
You can always create a backup of the current
.csproj
; then slap the standard SDK shell in there and piece it together after the fact.
I've found that to be faster than using the conversion tool out there.I've just gone through it, there are 27
.csproj
files
Should I convert all of them, or just the main .csproj
Alright, let me try this, and I'll get back to you on how it goes
I think just the one you're tying to build with
dotnet
should be fine (though I'm not 100% on that)
Better for consistency to do them all at some point though.
Be sure to make a backup of your file before starting ๐I'll take a backup of the whole project, just in case
27 isn't too bad; I had 100+ to do when I got started. I'm down to 20 left.
I'm slowly tackling them all ๐
Just the
.csproj
is fine; especially if you have source control in place.
Also
A nuance of SDK versus the old format
SDK will pull in all files and folders
So if you have files and folders excluded in the old format but still on disk they'll come in to play and you'll need to remove them.
I recommend having both so you can visually see the structure of the project in old and new forms for cross comparison ๐A coworker who worked on this project said that he had to upgrade it from 4.5 to 4.8 and the following year was a nightmare with lots of compatibility issues for the deployments, so that's what I'm specially scared of ๐ฌ
Project format doesn't impact your target framework ๐
Just make sure you target
net48
Gotcha
I love it because I can now choose to target multiple target frameworks easily without impacting our current end products which allows me to start testing things for upgrades to newer versions of .NET ๐
to be clear, if it's an ASP.NET 4.x project, you cannot use the SDK style
the .NET SDK just does not have all of the build logic needed for ASP.NET 4.x
GitHub
Add support for ASP.NET (non-Core) projects ยท Issue #2670 ยท dotnet/...
We routinely run into cases where the new project system and ASP.NET MVC 5 collide (or rather, don't) - I'd like to see support added. Here are the main use cases I'm aware of, I hope o...
That's awesome to know! I had that feeling there might be a nuance about old web projects I wasn't aware of ๐
Like, I know converting old projects with SOAP service references has been problematic for me. I don't think it's impossible, but just something I haven't overcome yet.
if you are OK with using an unofficial third-party solutions then someone has created a custom project SDK for ASP.NET 4.x projects https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb
GitHub
GitHub - CZEMacLeod/MSBuild.SDK.SystemWeb: This MSBuild SDK is desi...
This MSBuild SDK is designed to allow for the easy creation and use of SDK (shortform) projects targeting ASP.NET 4.x using System.Web. - GitHub - CZEMacLeod/MSBuild.SDK.SystemWeb: This MSBuild SDK...
this would let you use the new format and
dotnet build
but it's unclear how well the Visual Studio integration would workBig oof
Yeah it does not work well with the SDK idea
So back to the original question I guess
How do I do it with MSBuild ?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.