C
C#โ€ข8mo 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 ๐ŸŒŠ๐Ÿ’ƒ
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
RDasherโ€ข8mo 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 ๐ŸŒŠ๐Ÿ’ƒ
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
RDasherโ€ข8mo ago
I've just gone through it, there are 27 .csproj files Should I convert all of them, or just the main .csproj
Hazel ๐ŸŒŠ๐Ÿ’ƒ
<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
RDasherโ€ข8mo ago
Alright, let me try this, and I'll get back to you on how it goes
Hazel ๐ŸŒŠ๐Ÿ’ƒ
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
RDasherโ€ข8mo ago
I'll take a backup of the whole project, just in case
Hazel ๐ŸŒŠ๐Ÿ’ƒ
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
RDasherโ€ข8mo 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 ๐ŸŒŠ๐Ÿ’ƒ
Project format doesn't impact your target framework ๐Ÿ™‚ Just make sure you target net48
RDasher
RDasherโ€ข8mo ago
Gotcha
Hazel ๐ŸŒŠ๐Ÿ’ƒ
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โ€ข8mo 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โ€ข8mo 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 ๐ŸŒŠ๐Ÿ’ƒ
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โ€ข8mo 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โ€ข8mo 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
RDasherโ€ข8mo 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โ€ข8mo 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
More Posts
โ” How can I make a Console app with cool text that when displayed slowly writes whateverI'm trying to make a little story console app and I want to make the wording so that when you want tWhy is it not calling the OnCollisionEnter method?"'cs using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponeโ” โœ… using Xunit; does not work in visual studioAs far as I was aware its shipped with .Net when u install C# development, but when I try to import โ” GridSplitter like in WPF but in Mauiin WPF there is a GridSplitter control. When using drag & drop on that control you can use it to resโœ… my code dose not workhere's the code, whenever i try to complie it, it give an error main1.cs(14,12): error CS0029: Cannโ” View Designer for Forms AppHello I just recently created a Windows Forms App and accidentally closed the tab where you can dragโ” MvvmCross - MvxRecyclerView GetChildAt(position) returns nulli have a problem where GetChildAt returns null for all elements out of view ( i have a MvxRecyclerViโ” Finding the right algorithm for this task ๐Ÿค”Hello ๐Ÿ‘‹ I'm quite **new** to **C#** and still don't know which algorithm is used when, what it doeโ” How would one convert string to int?I have a string "1.65" for example which I would want to convert to a int with the value 1.65โ” Android SDK location issues in JetBrains RiderHello there! I'm starting learning Xamarin framework. I have MacOS operation system and use JetBrai