Search code examples
c#visual-studioprojects-and-solutionscsproj

Adding custom information to CSPROJ files


As part of our development life cycle we have a number of process that we run against the C# source in our projects.

The processes are driven off a GUI that currently reads the *.csproj file to find the source files used within the project. This works fine.

We now have a new requirement to provide some validation processes that require a call out to a web-service. The web-service needs to be provided with some credentials that are project specific. Ideally we could enter and store these credentials within the *.csproj file but I don't see a means of extending it - is there?

We don't really want to introduce a new config. file just for these settings if we can help it. Is it possible to store information like this is the *.csproj file, if not is there any other place to put it.

thanks


Solution

  • The .csproj file is basically an MSBuild file, as such you can extend it with custom values. If you right-click on a project in Visual Studio and choose "Unload Project", the project will "grey out" and you can then right-click again and choose Edit [ProjectFileName].csproj. You can then add something similar to the following:

    <PropertyGroup Label="Custom">
      <Badger>1</Badger>
    </PropertyGroup>
    

    This should be persisted when the project is modified (i.e. files added/removed) and you can retrieve the values from the file, using the method of your choice.