Your official information source from the .NET Web Development and Tools group at Microsoft.
I’ve written a few blog posts on how to exclude files from publishing/packaging. In each of these posts you’d have to be familiar with MSBuild and the Web Publish process. I’ve been looking for a much simpler way to exclude files/folder from publishing.
When using git you can easily exclude files and folders using a .gitignore file. Inside the .gitignore file on each line you can add a pattern that matches files/folders to be excluded from the repository. For example take a look at the sample .gitignore file below.
# Folders to ignore #
# Known files to ignore always #
In the .gitignore file above you can see how easy it is to exclude files and folders from publishing.
I thought it would be cool if we had the ability to exclude items from publishing this easily. Now we do!
I’ve created a NuGet package which solves this exact issue. With a web project opened try out the following.
You should see that the publish operation skips the files and folders which match the patterns in publish.ignore.
Some notes regarding the implementation here. The publish.ignore file is only supported at the root folder. .gitignore has support to drop .gitignore files in the root as well as subfolders. Currently publish.ignore is not supported in sub folders. This is something that can be implemented if there is enough interest here.
You may be wondering why I named the file “publish.ignore” instead of .publishignore. The reason for this is that on Windows it is difficult to create file names which do not have a string prefixing the extension. You can create these files through the command line, but not through Windows Explorer or VS.
This project is all open source at https://github.com/ligershark/publish-ignore. If you have any problems you can file an issue there, and if you like you can contribute to the code as well!
If this is something that you’d like to see in the box please email me and let us know SayedHa@microsoft.com
Sayed Ibrahim Hashimi | @SayedIHashimi
Doesnt work for me.
The "ReadPublishIgnoreFile" task failed unexpectedly.
System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
at System.Collections.Generic.List`1.Add(T item)
at InlineCode.ReadPublishIgnoreFile.Execute() in c:\Users\Daz\AppData\Local\Temp\vwa1cuem.0.cs:line 116
Doesn't work for me either - same problem as below.
Hi Daz/Jim, I had a couple issues with the initial release. I've since updated the release to ensure you don't run into that bug. Can you try again?
FYI for items like this it would be better to open an issue on the project page github.com/.../issues. That way you can also track progress on those items.