Good day.

I publish my ASP.NET MVC 3 project to the server using WebMatrix 2. It is easy to use, it allows you to upload only modified files, but there is one big problem in it - it downloads all the project files. This is the source code, project file, files from debug compilation and more. Is it possible to somehow automatically cut these files from the download?

In the settings for publishing Visual Studio 2010 there is a handy option - Only the files needed to launch the application. I would like something similar.

    1 answer 1

    In general, I wrote myself a small program that copies only the necessary files. Source:

    using System.Collections.Generic; using System.IO; using System.Linq; namespace CopyMvcFiles { class Program { static string _sourceMvcDirName; static string _destMvcDirName; static void Main(string[] args) { string[] options = File.ReadAllLines("Options.txt"); _sourceMvcDirName = options[0]; _destMvcDirName = options[1]; CopyMvcDir("App_Data", ".mdf", ".dat"); CopyMvcDir("bin", ".dll"); CopyMvcDir("Content"); CopyMvcDir("Scripts"); CopyMvcDir("Views"); CopyMvcFile("Global.asax"); CopyMvcFile("Web.config"); } static void CopyMvcFile(string fileName) { string sourceFileName = Path.Combine(_sourceMvcDirName, fileName); string destFileName = Path.Combine(_destMvcDirName, fileName); File.Copy(sourceFileName, destFileName, true); } static void CopyMvcDir(string path, params string[] searchPatterns) { string sourceDirName = Path.Combine(_sourceMvcDirName, path); string destDirName = Path.Combine(_destMvcDirName, path); CopyDir(sourceDirName, destDirName, searchPatterns); } static void CopyDir(string sourceDirName, string destDirName, params string[] searchPatterns) { if (!Directory.Exists(sourceDirName)) { return; } if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } IEnumerable<string> files; if (searchPatterns.Length == 0) { files = Directory.EnumerateFiles(sourceDirName); } else { files = GetFiles(sourceDirName, searchPatterns); } foreach (string file in files) { string fileName = Path.GetFileName(file); string destination = Path.Combine(destDirName, fileName); File.Copy(file, destination, true); } var directories = Directory.EnumerateDirectories(sourceDirName); foreach (string directory in directories) { string dirName = Path.GetFileName(directory); string destination = Path.Combine(destDirName, dirName); CopyDir(directory, destination, searchPatterns); } } static IEnumerable<string> GetFiles(string sourceDirName, params string[] searchPatterns) { return from file in Directory.EnumerateFiles(sourceDirName) let extension = Path.GetExtension(file) where searchPatterns.Contains(extension) select file; } } }