Skip to content

Instantly share code, notes, and snippets.

@mchandschuh
Last active March 15, 2021 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchandschuh/7e5bf9edfb015059c034ae0931e0cda2 to your computer and use it in GitHub Desktop.
Save mchandschuh/7e5bf9edfb015059c034ae0931e0cda2 to your computer and use it in GitHub Desktop.
Visual Studio Project Type to Replace the Solution Items Folder

Visual Studio Project Type to Replace the Solution Items Folder

When adding miscellaneous items to a visual studio solution, the files end up getting added under this Solution Items folder. What's particularly terrible about this is it's total disconnect from the underlying file system. These files define a shared project that will automatically add all items in its project directory to itself while maintaining the underlying file structure. Currently I'm using this for the convenience of being able to access related files, such as configuration and scripts, easily from within visual studio. I think that this type of project also allows every other project to reference these files, but I'll need to look into this bit more. I'll update this readme if any unexpected use cases are found.

Caveats

When adding files via the file system visual studio doesn't immediately display them, which is lame. Reloading the project makes them visible, but obviously that defeats the entire purpose. We're trying to be lazy here damnit! It's a real shame since this exact same syntax works in normal c# projects, which I would use for this purpose, except for having to update the build configuration to remove it from the build. hmm... might be worth, I really don't want to have to reload each time I add a file -- it's silly.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>9eff0ae0-06b7-4389-a03e-1059889392ab</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>project-name</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)**\*.*" />
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>9eff0ae0-06b7-4389-a03e-1059889392ab</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="project-name.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment