C
C#2y ago
Anton

What should I use to operate on solution files

I need an API to be able to parse, modify, and write back solution files. I know MSBuild has some internal classes for this, but I've also heard there are JetBrains libs for this. I couldn't find the latter, while the first on is kinda messy. Any suggestions?
18 Replies
Anton
Anton2y ago
Ideally it would be like a solution file builder, which I could add projects to anyone?
Thinker
Thinker2y ago
I think you could use the Microsoft.CodeAnalysis.Workspaces APIs for this It provides methods to get the contents of a solution file and pretty much everything else you could possibly ever want to know about a C# solution.
Anton
Anton2y ago
I'll check it out
mtreit
mtreit2y ago
Why do you need to manipulate solution files at all? Solution files are entirely optional as far as the SDK is concerned - for instance you can build any c# project without having a solution file at all. If you need one for Visual Studio, you can generate one on the fly using tools like slngen, which is what my team does. (I hate sln files, it's one of the worst file formats ever and should die in a fire)
Anton
Anton2y ago
for intellisense, basically I need to work on two disconnected set of projects at once (think client, server) I've looked at a bunch of CLI tools for this, they all kinda seemed terrible either doing too much, or too little, or not what i need what you're suggesting may work tho how do you configure the visual studio path on your job? it requires msbuild to be in path to run. It takes the visual studio devenv path via the -vs switch, but there is apparently no flag to configure msbuild path, except via the env vars, so it's unusable for linux, since there's no vs on linux. Do you just configure the path env var on all os's? seems messy @mtreit slngen seems to work ok, the only issue i have found but haven't investigated yet is that some projects fail to load correctly
mtreit
mtreit2y ago
I don't do anything with vs path. You don't need vs at all to build projects on either Windows or Linux. So not quite sure what you mean.
Anton
Anton2y ago
you do need msbuild to be on path, rather than passed to the program as an argument that is what i mean
mtreit
mtreit2y ago
Well, no, you can explicitly type the path to msbuild and invoke it directly, but yes typically when you install the SDK you will get your path updated to include the necessary tools so things like "dotnet build" just work
Anton
Anton2y ago
you can't type it directly, there's no flag for that, you have to pass it via env vars. like i mentioned, there is an option to pass the visual studio path, but it seems irrelevant on linux. I had to use msbuild locator nuget to be able to find it. and fyi dotnet cli does not include the full msbuild, it is only able to process csproj files, while slngen requires the whole thing, so just a dotnet cli installation is not enough
mtreit
mtreit2y ago
Ok I have no idea what you are talking about
Anton
Anton2y ago
just read through this thread, most of which I said is in there
Anton
Anton2y ago
GitHub
Auto-detect VS installation location · Issue #190 · microsoft/slngen
It would be great if the tool could auto-detect the location. I believe most users do not change the default. Or even use vswhere, e.g.: https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/1...
mtreit
mtreit2y ago
sln files (and slngen) are a Visual Studio thing, but you need neither to actually develop and build c# projects
Anton
Anton2y ago
why are you claiming it's a vs thing? because it opens the solution after it creates it? sln files are not just vs thing anymore
mtreit
mtreit2y ago
I disagree
Anton
Anton2y ago
they are the standard that ides use to understand project structure is there any other way to load multiple projects? I don't think so
mtreit
mtreit2y ago
Ok substitute IDE for VS then (assume you mean Rider as well? Or the like?) But the SDK and the ability to compile c# projects using things like msbuild has zero need for sln files
Anton
Anton2y ago
yeah now we're on the same page So it seems like some projects straight up don't have references to the runtime Not that they fail to load, rider loads them just fine, it's just that all my files in failing projects are covered in red for types not defined in my code, aka ones from the runtime. It can't resolve the namespace System, or even the void return type dotnet restore succeeds but does not help ah nevermind they stopped working individually too