I have a series of properties I need to set in ~15 projects. Is there a way to put these properties in a single file and have all the project files reference the one file using some sort of import directive rather than duplicating the properties in each project file?
EDIT: To clarify, I'm talking about <PropertyGroup>
elements within the csproj file. All the projects need the same series of <PropertyGroup>
settings. These elements set properties like DebugSymbols
or DefineDebug
, and are not used for referencing source files.
A CSPROJ file is a C# (C Sharp) programming project file created by Microsoft Visual Studio. It contains XML-formatted text that lists a project's included files and compilation options. Developers compile CSPROJ files using MSBuild (the Microsoft Build Engine).
If your program code is already in a Visual Studio project, open the project. To do so, you can double-click or tap on the . csproj file in Windows File Explorer, or choose Open a project in Visual Studio, browse to find the . csproj file, and select the file.
A PROJ file is a project file created in Microsoft Visual Studio, a software development tool used to create Windows programs and web applications. It contains XML-formatted text that defines a project's content, platform requirements, versioning information, and web server or database server settings.
The <Import>
element can be used for this, similar to how custom targets files are used.
The reusable file should look like this:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Properties go here -->
</PropertyGroup>
</Project>
Note that having the root Project
element with the xmlns
declaration is required - VS won't load a project referencing this file without it.
I've saved my properties settings in my solution directory as ProjectBuildProperties.targets.
To include the file in other projects, I've added this to the csproj files:
<Import Project="$(SolutionDir)ProjectBuildProperties.targets"/>
And it works!
You can create a shared MSBuild file that can be imported by all projects.
This post discusses this solution and demonstrate it here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With