سؤال

I have a nuget package that can be applied to any type of C# project.

It has a file that is added to the project as part of the package. The NuSpec looks like this:

  <files>
    <file src="Content\App_Start\StartUpCode.cs.pp" target="content\App_Start" />

I am using WebActivator to run the code in the file at application start.

I run into a problem when the nuget package is applied to several projects in the same solution. I get several instances of the StartUpCode.cs added, and as a result WebActivator runs the code several times.

How can I stop this code from being added to a project that is not web related? I.e. it's cool to add it to a WebAPI project, or a WebForms project, but not a class library.

هل كانت مفيدة؟

المحلول

I don't think there's anything in the Nuget spec that would allow you to do that easily. Maybe use a Powershell install script and detect the type of project it's being installed into and/or if the assembly has been referenced previously?

Personally, I'd split it into two Nuget packages. One with the business logic, and then another with the WebActivator dependency.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top