Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for csproj/msbuild to include files as optional content?

I have an optional config file in my application that is used for instance-specific configuration. The application works without it, and it is only necessary if you want to configure some additional features. It therefore shouldn't get included in the source control as every developer and client deployment doesn't need it and those who do will have different values.

I have a problem figuring out how to configure this for continuous deployment. I can generate the file on the build server without issues. However, since MsDeploy reads the csproj to determine which files to deploy, this file has to be tracked by my csproj to actually be moved to the deploy server. But if I have it tracked by my csproj, then it becomes no longer optional and I can't build the application without it. I'm using Mercurial which doesn't have a commit-one-version-ignore-subsequent feature (git's --assume-unchanged) so options seem pretty limited on that front. I am a very strong believer that it should be possible to clone a repo and run the project immediately, so I really don't like the idea of comitting something that cannot build.

Is there a way in the csproj file to indicate that a file should be included as content if present and ignored otherwise?

like image 444
George Mauer Avatar asked Jul 22 '16 23:07

George Mauer


People also ask

What does Csproj file contains?

csproj file contains the list of files in your project, plus the references to system assemblies etc. There are a whole bunch of settings - Visual Studio version, project type, Assembly name, Application Icon, Target Culture, Installation Url,... Everything you need to build your project.

How do Csproj files work?

CSPROJ files define a project's content, platform requirements, versioning information, and web server or database server settings. They also list the files that are part of the project.

What is a Csproj file extension?

What is a CSProj file? Files with CSPROJ extension represent a C# project file that contains the list of files included in a project along with the references to system assemblies.

What is private tag in Csproj?

The Private tag maintains the user-override to the "Copy Local" checkbox in the Visual Studio References folder. This controls whether the reference is used from the GAC or whether it will copy the referenced assembly to the build directory.


1 Answers

If this is the only .config file in the directory, then you can edit .csproj file manually to reference your file via file mask:

<ItemGroup>
    <Compile Include="*.config"/>
</ItemGroup>
like image 130
Igor Labutin Avatar answered Oct 13 '22 12:10

Igor Labutin