Convert old projects to new SDK
If you have an older C# project and you want a quick conversion:
1. Have your IDE (Visual Studio, etc) closed.
2. Move .csproj and .sln to mod root folder (or anywhere except Scripts folder).
3. Where .csproj was: delete bin, obj, .vs folders, and .ruleset and .user files.
4. Replace contents of .csproj with (ideally using anything but your IDE):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<Platforms>x64</Platforms>
<LangVersion>6</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mal.Mdk2.ModAnalyzers" Version="*" />
<PackageReference Include="Mal.Mdk2.References" Version="*" />
</ItemGroup>
</Project>
5. Open the .sln with a text editor and replace everything from EndProject to the end of file with:
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{YOUR_GUID_HERE}.Debug|x64.ActiveCfg = Debug|x64
{YOUR_GUID_HERE}.Debug|x64.Build.0 = Debug|x64
{YOUR_GUID_HERE}.Release|x64.ActiveCfg = Release|x64
{YOUR_GUID_HERE}.Release|x64.Build.0 = Release|x64
EndGlobalSection
EndGlobal
6. Still in the .sln find-and-replace YOUR_GUID_HERE with your GUID at the end of the Project() line.
For example:
Project("{First-GUID-do-not-use-this}") = "PaintGun", "PaintGun.csproj", "{385E79A8-1D69-47D1-975D-8C653CA37322}
You'd use the second one, 385E79A8-1D69-47D1-975D-8C653CA37322
.
And you're done! You can open the sln and continue programming.
If you have folders that contain .cs files you don't want to be compiled (like a Mod\Ignored), simply right-click that folder in VS and "Exclude from project", then ctrl+shift+S to save all files and you'll see it was added in the .csproj.