C
C#โ€ข14mo ago
RDasher

โ” 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 Core
20 Replies
Hazel ๐ŸŒŠ๐Ÿ’ƒ
Hazel ๐ŸŒŠ๐Ÿ’ƒโ€ข14mo ago
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.
RDasher
RDasherOPโ€ข14mo ago
It does not use the SDK format, I'm sure of that, cause out of habit the first thing I tried was dotnet build
Hazel ๐ŸŒŠ๐Ÿ’ƒ
Hazel ๐ŸŒŠ๐Ÿ’ƒโ€ข14mo ago
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.
RDasher
RDasherOPโ€ข14mo ago
I've just gone through it, there are 27 .csproj files Should I convert all of them, or just the main .csproj
Hazel ๐ŸŒŠ๐Ÿ’ƒ
Hazel ๐ŸŒŠ๐Ÿ’ƒโ€ข14mo ago
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<StartupObject>Namespace.Program</StartupObject>
</PropertyGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<StartupObject>Namespace.Program</StartupObject>
</PropertyGroup>

</Project>
RDasher
RDasherOPโ€ข14mo ago
Alright, let me try this, and I'll get back to you on how it goes
Hazel ๐ŸŒŠ๐Ÿ’ƒ
Hazel ๐ŸŒŠ๐Ÿ’ƒโ€ข14mo ago
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 ๐Ÿ™‚
RDasher
RDasherOPโ€ข14mo ago
I'll take a backup of the whole project, just in case
Hazel ๐ŸŒŠ๐Ÿ’ƒ
Hazel ๐ŸŒŠ๐Ÿ’ƒโ€ข14mo ago
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 ๐Ÿ™‚
RDasher
RDasherOPโ€ข14mo ago
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 ๐Ÿ˜ฌ
Hazel ๐ŸŒŠ๐Ÿ’ƒ
Hazel ๐ŸŒŠ๐Ÿ’ƒโ€ข14mo ago
Project format doesn't impact your target framework ๐Ÿ™‚ Just make sure you target net48
RDasher
RDasherOPโ€ข14mo ago
Gotcha
Hazel ๐ŸŒŠ๐Ÿ’ƒ
Hazel ๐ŸŒŠ๐Ÿ’ƒโ€ข14mo ago
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 ๐Ÿ˜„
reflectronic
reflectronicโ€ข14mo ago
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
reflectronic
reflectronicโ€ข14mo ago
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...
Hazel ๐ŸŒŠ๐Ÿ’ƒ
Hazel ๐ŸŒŠ๐Ÿ’ƒโ€ข14mo ago
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.
reflectronic
reflectronicโ€ข14mo ago
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...
reflectronic
reflectronicโ€ข14mo ago
this would let you use the new format and dotnet build but it's unclear how well the Visual Studio integration would work
RDasher
RDasherOPโ€ข14mo ago
Big 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 ?
Accord
Accordโ€ข14mo ago
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.
Want results from more Discord servers?
Add your server