Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify .NET project files and reference properties

I am developing an application (C#) which would read project properties/references (and properties of the references) from multiple csproj files, and modify their values.

However, the Reference properties like "copy-local" (the properties you see in the properties explorer when you click on a reference) cannot be found in those csproj files. Is there a way I can access them and modify their values programatically?

like image 279
aromore Avatar asked Oct 22 '25 18:10

aromore


1 Answers

Everything is in the XML project file - there's not really anywhere else that this information could be, and it has to be somewhere, right?

Here's an example I've quickly done for you. Copy Local is true by default for framework assemblies. When you set Copy Local to false, you get an XML element named private included for that reference which itself is set to false.

In this example System.Core is set Copy Local = false.

<Reference Include="System.Core">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
  <Private>True</Private>
</Reference>
<Reference Include="System.Web" />
like image 142
Kirk Broadhurst Avatar answered Oct 25 '25 10:10

Kirk Broadhurst