A language-agnostic project type for Visual Studio?
Asked Answered
E

3

10

I'm writing a piece of code that's just a bunch of JavaScript and JSON files -- it's a grunt plugin, rather than a website -- and I'd like to edit files and manage source control through Visual Studio.

I'm trying to construct a 'vanilla' msbuild project file -- not C#, not VB, etc because those files aren't valid in this kind of file. I can write a very simple MSBuild file with a .msbuildproj extension, but can't get it to load into VS2013, and can't find an example anywhere.

Anyone know how to put together an empty, language-independent project simply for file management?

Endaendall answered 28/2, 2014 at 20:13 Comment(6)
I usually use Web Site projects for this.Loggerhead
It should be in Xml, adhere to the MsBuild project file schema. You said you couldn't get it to load. How are you trying to load it?Foliole
Just use a solution and add the files as solution items? because those files aren't valid in this kind of file I doubt that is true, in my experience you can just add files of any type to any project. And set 'build action' to 'None' for instance.Bernettabernette
@Nick - I had a valid msbuild file with a .msbuildproj extension. It runs in MSBuild on the command line, but when I try to add it to a solution in VS, it complains. Since it's a supported type (it's there in the file filter under File | Add | Existing project) I thought I'd attempt to get it to work. A stripped-back .csproj file works, though, without VS complaining too badly.Endaendall
@Bernettabernette - The solution files angle is difficult to manage with a lot of files, because it doesn't deal with folders very well, or showing you missing files. You can certainly add any kind of file to a .csproj or .vbproj file, and that's what I've gone for at the mo (2014-03-05) but there is undocumented support for a project with extension .msbuildproj and I'd hoped to get that to work, assuming it was a little more generic.Endaendall
@Loggerhead - A web site project looks like a good angle. I've currently gone with a stripped-back csproj file (all the build targets replaced with empty ones) but a web site sounds like a better way of structuring javascript.Endaendall
N
3

I found the same msbuildproj extension and wanted to do something similar. I don't care about actually building in VS right now. I just want to include all files in some folders, alleviating the shortcomings of Solution Folders. So after some searching I found this post. With VS2017 in hand and making use of the new MSBuild project format introduced for .NET Core projects I was able to make the following to work for me.

<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <Content Include="*" />
    <!-- Use "**" for all sub-folders -->
    <!--<Content Include="**" />-->
  </ItemGroup>

  <!-- A temporary solution, import C# Visual Studio design time targets in order to be able to load the project in Visual Studio -->
  <PropertyGroup>
    <CSharpDesignTimeTargetsPath Condition="'$(CSharpDesignTimeTargetsPath)'==''">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\Managed\Microsoft.CSharp.DesignTime.targets</CSharpDesignTimeTargetsPath>
  </PropertyGroup>
  <Import Project="$(CSharpDesignTimeTargetsPath)" Condition="'$(CSharpDesignTimeTargetsPath)' != '' and Exists('$(CSharpDesignTimeTargetsPath)')" />
</Project>
Nonparticipating answered 9/11, 2017 at 17:10 Comment(0)
A
1

You are mostly right:

  • Visual Studio projects (almost all modern types, that is) are MSBuild projects. But, Visual Studio only loads projects for which it has extensions. You can't load arbitrary MSBuild projects. (Of course, you can always edit an MSBuild file as XML. If it is already loaded as a project, you have to unload it first to edit it.)

  • With some project types you can't add whatever type of file you'd like. For example, WiX projects don't allow you to add T4 template (.tt) files. It's a shame. You can however, edit the project to add them, which shouldn't break anything. But it's really up to the author of the project type extension. Nonetheless, I haven't found any file that I can't add to a C# and Visual Basic .NET project.

As SLaks commented, Web Site projects do allow any type of file to be added and should work for your case.

Alberta answered 1/3, 2014 at 21:51 Comment(1)
Thanks for your comments, Tom. What I was going for was an '.msbuildproj' file -- if you do File | Add | Existing Project, the filter includes this extension alongside csproj, vbproj, etc. I've currently gone for a stripped-back csproj file but I'll look at Web Site.Endaendall
S
0

With modern Visual Studio versions you can now create a language-agnostic .msbuildproj project (as you suggested) using the Microsoft.Build.NoTargets project type. It can also be added to a solution from the Visual Studio user interface without any issue. Here it is a sample project that just runs a powershell script:

<Project Sdk="Microsoft.Build.NoTargets/3.7.0">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command &quot;Write-Output HelloWorld&quot;" />
  </Target>
</Project>

The only awkward aspect about this solution is that a TargetFramework property must be defined, but hopefully this may be fixed at some point.

Stertor answered 2/2, 2024 at 15:1 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.