1

At this time, my .csproj files contain the XPath /Project/PropertyGroup/VersionPrefix and that determines the version for the nuget packages. However, I would prefer to read this version prefix from a shared file, as it will be common for 3 or 4 projects, each of whom have their own .csproj files.

In other words, instead of having

<VersionPrefix>2.0.0</VersionPrefix>

we would prefer to have something like

@@include ../../version.xml

and this version.xml contains the line above which will be substituted.

I am sure there would be multiple ways to achieve this but cannot fathom exactly how. Help would be appreciated.

1 Answer 1

5

You can create a file named Directory.Build.props in the folder hierarchy above all your projects (e.g. next to the solution file) and put shared properties in there:

<Project>
  <PropertyGroup>
    <VersionPrefix>2.0.0</VersionPrefix>
  </PropertyGroup>
</Project>

MSBuild will automatically find and import this file. (you may need to re-open your editor / visual studio). See MSBuild's Customize your build documentation for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.