简体   繁体   中英

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM