How to pack a directory containing static files using nuget.exe? - nuget

How to pack a directory containing static files using nuget.exe? If I would have a csproj file I would be able to generate a nuspec necessary to run nuget pack command, but how to do it when I just have a directory of content files?

Related

How to exlude automatically added files from nuget?

When you write nuspec file it is possible to use files tag and select some files with exclusion of some unwanted ones. However how I can exclude files that nuget adds automatically?
For example I have a project with with such file:
Schema\Configuration.xsd
nuget decides to add it to package and I cannot get rid of it (from the package).

Is it possible to change where a nuget package adds files to a project?

If I add a nuget package Foo it might add files to the Content folder in my project.
Content
|
- foo.js
- foo.min.js
- foo.map
What if I wanted something like:
Content
|
- Foo
|
- foo.js
- foo.min.js
- foo.map
Most of the other questions I have found are talking about the location of the packages folder - is something like the above possible?
NuGet does not put the files into a Content folder inside your project unless that is the folder you used. You can put the files in any subdirectory inside the project. The jQuery NuGet package puts its files in a Scripts subdirectory, for example, and it has the folder structure inside its NuGet package (.nupkg):
Note that the Content directory here is just tells NuGet that it should put the files in the project directory. It does not add the files into a Content directory but instead adds them inside a Scripts directory inside the project.
By default, the Nuget Package Manager puts all the .js files inside the 'Scripts' folder and .css files inside the 'Content' folder. But if you want to create a subfolder and categorize your packages, you will have to manually do that. Create a sub folder and move the files manually to it.

Nuspec files from nested directory

I have such file structure:
MyProject/MyProject/bin
I am creating Nuget package via nuspec file. So to add bin folder, I have added this command:
<file src="MyProject/MyProject/bin/**" target="bin"/>
But as a result I am receiving this file structure:
bin/MyProject/MyProject/bin
Is there a way to copy files directly into bin folder, without creating nested directories? So my output would be like simple:
bin

Why NuGet Package manager Download/Copy Packages on multiple Locations?

I have Directory Structure like -
Projects
.nuget
NuGet.exe
NuGet.config
NuGet.targets
**packages (I want to download package for different solution HERE ONLY)**
Sources
Applications
App1
App1.sln (Solution File)
**packages (NuGet downloads packages here first then copies to expected folder, WHY??)**
App1 (Porject Directory)
App1.csproj
App2
App2.sln (Solution File)
**packages (NuGet downloads packages here first then copies to expected folder, WHY??)**
App2 (Porject Directory)
App2.csproj
I have referenced .nuget folder in each solution using following code
Project("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}") = ".nuget", ".nuget", "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}"
ProjectSection(SolutionItems) = preProject
..\..\..\.nuget\NuGet.Config = ..\..\..\.nuget\NuGet.Config
..\..\..\.nuget\NuGet.exe = ..\..\..\.nuget\NuGet.exe
..\..\..\.nuget\NuGet.targets = ..\..\..\.nuget\NuGet.targets
EndProjectSection
EndProject
In every project file (.csproj), I have referenced common NuGet.targets using,
<Import Project="..\..\..\..\.nuget\NuGet.targets" Condition="Exists('..\..\..\..\.nuget\NuGet.targets')" />
In NuGet.config, I have added following line so that it should (must) copy packages in EXPECTED folder ONLY
<add key="repositoryPath" value="..\packages" />
I have mapped Projects folder with TFS and it asks me to add files on both locations because of above problem
NuGet will look for the NuGet.config file based on the current solution's directory.
So taking your App1 solution if the Projects directory is in c:\Projects then your App1.sln file will be in the c:\Projects\Sources\Applications\App1 directory. Now NuGet will look for the NuGet.config directory in:
c:\Projects\Sources\Applications\App1\.nuget\NuGet.Config
c:\Projects\Sources\Applications\App1\NuGet.Config
c:\Projects\Sources\Applications\NuGet.Config
c:\Projects\Sources\NuGet.Config
c:\Projects\NuGet.Config
c:\NuGet.Config
After this it then looks in machine wide locations but I will ignore these for now.
Looking at your directory structure the Projects.nuget directory will not be checked by NuGet. It is not a parent of any of the solution directories.
I would look at putting a NuGet.Config file with the repositoryPath setting in the Sources directory or the Projects directory (not in the .nuget directory). Or having two NuGet.Config files, one in the App1.nuget directory and one in the App2.nuget directory.

Nuget: How to copy a files to root folder without including in project

If you put any files in the Content folder of a Nuget package, during installation these files are:
Copied to the root of the target project and
Included in the project.
Is there any way to make Nuget skip action 2, i.e. to copy them but not include them in the project?
I know I can do this with a Powershell script that goes in and removes the files from the project. But I don't think that's a very robust method.
Can I achieve this without relying on Powershell?
You can try adding your contents directly in the package instead of the "contents" folder.
Files outside "contents" would be ignored by NuGet while trying to add content files.
Then you can do just the copying part using your powershell scr