adding visual studio project and inject files in the newly created project

Feb 26, 2012 at 7:41 AM

I 'm trying to create a nuget package which

1. adds a new classlibrary project to the open solution and

2. injects some predefined files in the newly added classlibrary project.

I can do this my using "DTE" code:

 Add-Type -Assembly EnvDTE100
$solution = get-interface $dte.solution ([EnvDTE100.Solution4])
$templatepath= $solution.GetProjectTemplate("", "CSharp")
$NewProjectName= "MyNewClassLib"
$solution.AddFromTemplate($templatepath, "<path to current solution>\MyNewClassLib", "MyNewClassLib", $false)
$classLibProject = Get-Project $NewProjectName

My point is that i would rather like to inject files for the new project via the regular nuget mechanism, but I didn't find a way to set the "current project" to the newly added project in such a way that the nuget files in the package are injected in the classlib rather than in the project on which nuget is initialy run.

Would be great if someone could point me in the right direction (or point to a similar nuget package).



Feb 27, 2012 at 4:12 PM

I don't believe there is any way to set the current project (that being the project against which NuGet is currently operating), but @dotnetjunky can correct me if I'm wrong. NuGet, including our extensibility points, isn't designed to accommodate adding new projects to the solution; I would expect friction and frustration when trying to do so.

Feb 27, 2012 at 6:56 PM

Yes, @drewmiller is right. We don't expose any public API to set the default project.