I created a multi-project template and connected it with a wizard.
Everything is working fine, and I can restore packages using update-package -reinstall
in the package console manager.
I'm trying to add Elmah & ApplicationInsights with a condition in the .csproj
file of the template, so that it'll add Elmah or ApplicationInsights based on the answer to the wizard.
I tried doing the following which didn't work:
<Reference Include="elmah, Version=1.2.2, Culture=neutral" Condition="$($ext_custommessage$) == 'LAN'" />
I tried adding it in a <ItemGroup>
element but no dice.
What should I do in this case to add these packages to the .csproj
file?
CodePudding user response:
I think that the easiest way to do this is to have both packages installed. Then only configure ELMAH when running on localhost. I'm guessing you have web.config
and web.release.config
files. You then include ELMAH config in the web.config
one but remove it using XDT in the web.release.config
one. It's basically described in reverse here: https://docs.elmah.io/use-multiple-logs-for-different-environments/#logging-to-elmahio-from-production-only (only logging from production). Also, the example is for elmah.io (cloud version of ELMAH) but you can use any logger implementation you'd like. I'm not sure how you'd configure AI but you can probably use a similar approach there.
CodePudding user response:
I achieved the goal by doing the following:
Added two custom parameters to the custom wizard that's connected to the templates. One parameter for the package name/id and one for the package version. The values of these parameters are set based on user's choice in the wizard. These two parameters are passed using
Dictionary<string, string> replacementsDictionary
in theRunStarted
method in the custom wizard.Added the following line to
packages.config
file that's in the project template folder:
<package id="$package$" version="$version$" targetFramework="net48" />
$package$
is the parameter that has the package name.
$version$
is the version of the package.
I also added the following to the .vstemplate
file of the project:
<ProjectItem ReplaceParameters = "true" TargetFileName="packages.config" >packages.config</ProjectItem>
This is needed so that the parameters get replaced with the wanted package information.
Once user runs update-package -reinstall
in package console manager, the required packages will be installed as well as the other ones will be restored.