I'm busy creating a Nuget package that will be used internally only which installs other packages being dependencies, Ninject being one of them.
After installation, a NinjectWebCommon.cs file is added to the App_Start folder of the project. My custom package requires that file to be modified in the following way: (only showing part of the code)
//code above removed...
using Ninject;
using Ninject.Web.Common;
//modified this part already - refer to block quote 1 on how i did it
using mylibrary.whatever;
//code below removed...
I managed to insert the line "using mylibrary.whatever" by using install.ps1 (as per the Nuget package convention) in the following way, albeit not that sophisticated (VERY little experience with powershell):
Blockquote 1:
$p = get-project;
$p = Split-path $p.filename;
$p += "\App_Start\NinjectWebCommon.cs";
(Get-Content $p) | foreach-object {$_ -replace "using Ninject.Web.Common;", "using Ninject.Web.Common;`r`n using mylibrary.whatever;"} | Set-Content $p;
Now that's quite ok for a 1 line addition.
My problem comes in with changing this section...
// code above removed...
private static void RegisterServices(IKernel kernel)
{
}
// code below removed...
to this...
// code above removed...
private static void RegisterServices(IKernel kernel)
{
kernel.Load(new mylibrarymodule());
}
// code below removed...
To complicate things a little more, this NinjectWebCommon.cs file could be changed in the same manner by x amount of internal Nuger packages. So
// code above removed...
private static void RegisterServices(IKernel kernel)
{
kernel.Load(new mylibrarymodule());
}
// code below removed...
could also become
// code above removed...
private static void RegisterServices(IKernel kernel)
{
kernel.Load(new mylibrarymodule());
kernel.Load(new myotherlibrarymodule());
kernel.Load(new anotherlibrarymodule());
}
// code below removed...
Any help would be appreciated as powershell is not one of my strong points...