Skip to content

Do I have to know CSPROJ VBPROJ

Ewen edited this page Oct 26, 2015 · 2 revisions

Yeah but no.

If you weren't good at XML & csproj files before then you will probably learn a reasonable amount about it using this - expect to occasionally break things. If you're not willing to occasionally cut your fingers on an angle-bracket then this is not for you. Git will get you out of most trouble but knowing a little about the internals of .csproj (related to MSBuild) will help. It's XML, you won't bluescreen anything if you edit it and get it wrong. Just make sure you commit often. Most things need to be inside a <PropertyGroup> or <ItemGroup>. <ItemGroup> is the one we're interested in messing with. Visual Studio has a way of changing things you've edited, especially when it comes to wildcards - I like to add a copy of my edits as an XML comment to preserve the original although the commit history is just as good for this so I'll stop doing that. If you are using Notepad++ then try this Syntax Highlighter.

So far there has been no magic bullet for write once, build on many tenuously-related platforms. I have tried a plethora of build configs inside one project (my record is 72) but that breaks catastrophically if you add a Nuget reference or something like that. I think the Solution (sorry, I should stop that) lies in separate projects with build specifics hauling their core source code in from a one-version-of-the-truth. You can't just import a whole Project because that drags in all the build settings, references etc. At least with this method the fragility is in the destination csproj, not in the original source. I can only automate so much, you will still have to get your hands a little dirty.

Diffing the source and destination projects should give you an idea on how it went and what actually happened.

####This is the bare-bones placeholder with no options specified, look for it in the diff...

<!-- CodeLinker -->

<!-- EndCodeLinker -->

oh, you're still here.
ok
um
Don't be afraid to edit XML .csproj files. For instance, this works ...

<Compile Include="$(Codez)\z.Libraries\diff-match-patch\DiffMatchPatch\**\*.cs">
<Link>Libs\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>

...and will give you all the C# files from the source folder, and subfolders, as linked files in your destination project. $(Codez) is a Windows Environment Variable I use on my PCs. I also could have used \*.* at the end. This is one of those things Visual Studio might break on you, adding a file in the folder full of wildcard-linked files may break them out to separate entries. Or not. Depends on the wind.

Clone this wiki locally