Search code examples
c#vb.netnugetnuget-packagenuget-spec

Distinguish project languages for Nuget source code packages


Let's say I want to build a Nuget package which puts source code files to the Visual Studio projects it gets installed to. Well this works pretty fine with the "content"-approach.

That means I can bring these files in the following folder structure to automatically add them to the file system and the VS-projects as well:

.\ThePackage.nuspec
    └ content\TheFile.cs
    └ content\TheOtherFile.cs

With a package like this, Nuget will automatically add the source code files to the projects directly. However, it does that with both files, so I found no way to make that conditional.

"Why?" you may ask - well, I don't really have two cs files. I have one for C# and one for Visual Basic doing the same in different languages. So I need to distinguish between C# and Visual Basic project files. The content approach above with a structure like this ...

.\ThePackage.nuspec
    └ content\TheFile.cs
    └ content\TheFile.vb

... will cause a mix with the cs and the vb file in each project, of course.

Is there a way to tell Nuget that I just want to have the cs file in C# projects and the vb file in Visual Basic projects without the need to provide two Nuget packages like ThePackage for C# and ThePackage for VB?


Solution

  • You can add a init.ps1-file to your nuget-package that is executed on installation. There you can place some logic like detect what language is used in the project etc and removed/add the unwanted or wanted files