In Visual Studio there are times when it makes sense to share a non-code file between multiple projects in a solution. One such scenario is when using the static code analysis tool, StyleCop. Among the rules StyleCop can enforce is that every source file in a project must contain a standard header including company name and copyright. For each source file, company name and copyright must match values specified in the StyleCop configuration file, stylecop.json. So the file to share between multiple projects is stylecop.json which can be added at the solution of a Visual Studio solution such as the following:
The solution contains two project, ADotNetConsoleApplication and ADotNetStandardClassLibrary. The goal is to add Solution Items\stylecop.json to both projects. To to this right click on the project, ADotNetConsoleApplication and select Add | Existing Item from the context menu displayed (see below):
When Existing Item is selected the following dialog is displayed (aptly named the Add Existing Items dialog):
Notice that the file filter is set to Visual C# Files. In order to see the stylecop.json file, change the filter to All Files (*.*) as follows:
Navigate in the Add Existing ITems dialog to the root of the solution and select the file stylecop.json.
Notice next to the Add button on the dialog there is a downward pointing arrow. Click on this arrow:
Click on Add As Link and once this is selected the file will show up in the project:
The master copy of the file is at Solution Items\stylecop.json and the linked version is under the ADotNetConsoleApplication project. Too add stylecop.json as a linked file to the ADotNetStandardClassLibrary project is a matter of repeating the steps shown above.
No comments :
Post a Comment