I've been rewatching the Great War series on youtube, and it struck me how critical railway lines were for supplying front lines, moving troops and such for the occupying german army.
To me, the Hindenburg line seems like an even more complex and involved task, yet they built up several dozens (or even hundreds) of kilometres of defenses, with multiple lines of trenches, concrete bunkers, garrisons for troops. Was building railway lines that much more difficult, or were there other reasons that prevented them from doing so?
Building a full-on standard gauge railway is indeed an expensive undertaking, but the main problem is that railways are very static, very visible, and very much on the surface.
This means that they are massively vulnerable to artillery, and with some guns having ranges of up to 20km, building expensive standard gauge railways to supply the front line is obviously a sub-optimal use of resources as they'd be destroyed faster than they could be built.
Now this doesn't mean that rail wasn't used for logistics close to the front, but it tended to be narrow-gauge rail rather than standard-gauge.
All major combatants in the west used narrow-gauge rail (600mm was standard) to assist with the transport of troops, shells, casualties etc.
It had the advantage of being relatively inexpensive and could be laid in the same way you might lay a model railway - prefabricated section 5m in length and weighing 100kg could quickly be laid by teams of unskilled or semi-skilled labourers (one of the jobs of the ~92,000 Chinese labourers attached to the BEF).
Narrow-gauge also had the advantage that it could be taken up and re-laid to provide logistical support to wherever on the front needed it most.
British, French, and Germans each produced thousands of prime-movers, steam, diesel and petrol powered, but carts could be hand hauled or horse/mule drawn as well.
A small section of narrow-gauge rail is preserved on the Somme, the Froissy Dompierre Light Railway, which I had dubious pleasure of catching a ride on a few years ago - it was damned uncomfortable!