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

Feb 26, 2012 at 6: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("ClassLibrary.zip", "CSharp")
$NewProjectName= "MyNewClassLib"
$solution.AddFromTemplate($templatepath, "<path to current solution>\MyNewClassLib", "MyNewClassLib", $false)
$classLibProject = Get-Project $NewProjectName
$riaProject.ProjectItems.AddFromFileCopy("<fullpathtofiletoadd");

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).

thanks

paul.

Feb 27, 2012 at 3: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 5:56 PM

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