Should content from a NuGet package be added with 'BuildAction=None' in csproj??

Oct 5, 2011 at 11:01 AM

I use NuGet internally as a repository of frequent used modules. These modules often have dependencies to other modules. Every module might have a collection of aspx/ascx. Then I use the option provided by nuget.exe to pack a project as a nuget package.

'nuget.exe pack' takes the packages.config, project.nuspec and project.csproj in consideration when creating the package. Now Im facing a problem with having the same 'content' in multiple packages - this might be a problem when upgrading at a later stage.

 

Create a Project-A.csproj with a page: pageA.aspx

Result:

  • Project-A.nupkg
    • lib
      • Project-A.dll
    • content
      • pageA.aspx

Now; create Project-B.csproj with a page; pageB.aspx, and add package Project-A.nupkg

Result:

  • Project-B.nupkg
    • lib
      • Project-B.dll
    • content
      • pageB.aspx
      • pageA.aspx
    • dependencies
      • Project-A

This might lead to a problem when updating at a later stage, but if adding a package added content with BuildAction=None pageA.aspx would not become a part of Project-B.nupkg and problem is solved.

There might be problems related to adding content with BuildAction=None, but I would guess that if there are content from a package that required compilation that the content is already compiled into the assembly.

Is this an issue anyone else are experiencing or am I the only one using NuGet like this?

Coordinator
Oct 5, 2011 at 5:23 PM

Just so I understand, the files pageB.aspx is added with BuildAction = Compile? 

Oct 5, 2011 at 7:34 PM

No - "NuGet.exe pack" looks for content that have BuildAction=Content (which is default for aspx/ascx,++)

Coordinator
Oct 5, 2011 at 7:44 PM

Ok, that behavior is by design. If you want the content to be added to the NuGet package, you need to set the BuildAction = Content. NuGet Pack looks at the OUTPUT of the project being built. NSetting the Build Action to Content causes Visual Studio to copy the content to the output. That's how NuGet knows that it should be included.

Oct 5, 2011 at 8:45 PM

Yes, I know - and I use that in Project-A to create a NuGet package with pageA.aspx, but I would like NuGet to exclude pageA.aspx when creating the package for Project-B.

When a user then installs the Project-B package he will get Project-A first (because of the dependency) wich includes pageA.aspx, then Project-B with pageB.aspx. 

My ultimate goal is to tell the 'NuGet.exe pack' command to exclude content files that have been added to the current project by dependencies - and my initial thought was to use the BuildAction to accomplish this. But there might be better ways...

Developer
Oct 5, 2011 at 9:22 PM

Have you tried the exclude file on nuget pack? 

http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command

Oct 6, 2011 at 5:35 AM

Yes, but it will be a pain to track every item that's added and add them to the exclude list - I was hoping that NuGet could take care of this for me ;-)

Oct 6, 2011 at 6:00 AM

I agree that ideally that would be the correct thing to do. Currently, we don't keep track of the fact that some of the content files come from different packages, making it hard to do the right thing at pack time. But conceivably it could happen at some point.

Coordinator
Oct 6, 2011 at 8:53 PM

The only way it will happen is if there's an issue for that. So please log a bug. :)

Secondly, if someone were to submit a pull request with the feature implemented along with unit tests, that would go a long way to getting it into the product. :)