Skip to content

Instantly share code, notes, and snippets.

@pakrym
Last active February 22, 2016 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pakrym/d9262e46a1d780ce9652 to your computer and use it in GitHub Desktop.
Save pakrym/d9262e46a1d780ce9652 to your computer and use it in GitHub Desktop.

Sample project structure

Views/Shared/Index.cshtml
Views/_Layout.cshtml
Images/Logo/Logo.png
Images/Logo/LogoBW.png
Images/Screen1.png
Shared/Helper.cs
Shared/Helper.vb
Shared/~Helper.cs
Scripts/publish.cmd
Scripts/remove.cmd
build.cmd

Build output

Views/Shared/Index.cshtml
Views/_Layout.cshtml
Scripts/publish.cmd
Scripts/remove.cmd
Scripts/build.cmd

Source includes

Shared/Helper.cs

Embedded Resources

RootNamespace.Images.Logo.Logo.png
RootNamespace.Images.Logo.LogoBW.png
RootNamespace.Images.Screen1.png

project.json file

project.json can contain a contentFile section.

{
    ...
    "packageOptions":
    {
        "packInclude" : {},
        "contentFiles":
        {
            "images/**/*.png": { 
                "buildAction": "EmbeddedResource", 
                "copyToOutput": false 
            },
            "shared/*.cs": {
                "exclude": "~*.cs", 
                "buidAction": "compile", 
                "target": "dotnet5.4",
                "language":"cs" 
            },
            "Views": 
            { 
                "copyToOutput": true 
            },
            "*.cmd": 
            { 
                "flatten": true, 
                "outputPath": "scripts",
                "copyToOutput": true 
            }
        }
    }
    ...
}

Section

Content files section can be object where keys are treated as include attribute or array of objects.

    "contentFiles":
    {
        "*.txt": 
        { 
            "copyToOutput": true 
        },
        "*.md": 
        { 
            "copyToOutput": true 
        }
    }
    "contentFiles":
    [
        { 
            "include": ["*.txt", "*.md"], 
            "copyToOutput": true 
        }
    ]

Attributes

Attribute Description
include [Required attribute] String or array of strings. Include provides either a file path or a wild card path. Examples: **/*, **/*.cs, any/any/myfile.txt, **/net*/*.
exclude String or array of strings. Exclude provides either a file path or a wild card path. All matching files will be excluded from the include.
buildAction Build action taken by msbuild for the content items. Examples: None, Compile
copyToOutput If True the content items will be copied to the build output folder
outputPath Sub folder name inside build output folder to copy files to is relative to build output folder
flatten If False the content items will be copied to the output folder using the full folder structure from the nupkg. By default paths are relative to project.json location
language Use this content file node only if referencing project targets specific language. Examples: any, cs, vb, fs
target Use this content file node only if referencing project targets specific framework. Examples: any, net451, dotnet5.4

Attributes defaults

Attribute Value
buildAction None
copyToOutput True
flatten False
language any
target any

There is discussion around default buildAction and copyToOutput values: @yishaigalatzer argues that default should not be different from .nuspec default which is Action=Compile, Copy=false or shoud force user to select build action.

@pakrym
Copy link
Author

pakrym commented Jan 25, 2016

@pakrym
Copy link
Author

pakrym commented Jan 25, 2016

@livarcocc
Copy link

What is the reason for this extra packageOptions section?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment