简体   繁体   中英

Visual studio 2013 deploy file on save

I am building a PHP web site with visual studio 2013. For testing purpose I have a directory files in project root which have a few ten thousands files (1000GB) and a few thousands directories. My Visual studio 2013 is not responding because Solution explorer is scanning files directory.

My first idea was to exclude files directory from project, but no idea how to do that .

My second idea is to move project source away from Apache document root dir (where all those files are). But now I need to publish project or file(.html, .js) always when I made some changes. This is very time consuming. Is there a way to publish automatically on file save or on every save make copy to different folder? Project files and Apache document root are both on same machine.

I know how to achieve what you expect with VSPackage Extensions, provided by Visual Studio 2013 SDK . You can develop extension which listens to document's save event and than can do whatever you like with the file (eg. move it's copy to your Apache application directory). You can also subscribe to Add, Remove, Rename, Open, Opening and Close events.

Check this link: http://msdn.microsoft.com/en-us/library/dn246938.aspx , and start from How do I start developing VSPackage extensions? section.

Create extension skeleton as described in steps, test it, and add lines like theese:

    public void OnItemRenamed(EnvDTE.ProjectItem projItem, string oldName)
    {
        Log("[Event] Renamed " + oldName + " to " + Path.GetFileName(projItem.get_FileNames(1)) + " in project " + projItem.ContainingProject.Name);
        //add your logic here
    }

    public void OnDocumentSaved(Document document)
    {
        Log("[Event] Saved " + document.Name + " in project " + document.ProjectItem.ContainingProject.Name);
        //add your logic here
    }

    private void OnDocumentOpening(string documentpath, bool @readonly)
    {
        Log("[Event] Opening " + documentpath );
        //add your logic here

    }

    private void InitEvents() //remember to call it in Initialize()
    {
        DTE2 dte = (DTE2)GetService(typeof(DTE));

        Events2 dteEvents = (Events2)dte.Events;
        dteEvents.ProjectItemsEvents.ItemRenamed += OnItemRenamed;

        //remember to declare it
        _docEvents = dteEvents.DocumentEvents; // defend against Garbage Collector
        _docEvents.DocumentOpening += OnDocumentOpening;
        _docEvents.DocumentSaved += OnDocumentSaved;
     }

I know it's like taking a sledgehammer to crack a nut, but it is some kind of solution.

I am wondering why your project is so big? Maybe it contains large amount of user-generated data (images/other files) which can be moved to other folder/machine? If yes (and you don't need them locally), check out a ProxyPass module for Apache and redirect theirs requests: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html ProxyPass /foo http://live.example.com/foo

...and I hope you have SSD disk ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM