locked
Project Structure/Deployment/Update Dilemma RRS feed

  • Question

  • User-1209063919 posted

    I have a project structure/deployment/update dilemma that I could really use some help with.

    I usually structure my applications in the following manner:

    Visual Studio Solution <ProjectName>.Solution
        Class Library <ProjectName>.Library
        Class Library Tests <ProjectName>.Library.Tests
        Web Application <ProjectName>.Web
        Web Application Tests <ProjectName>.Web.Tests

    I am developing a solution for multiple clients, who will be using an installable version of my web application (let's call: Application), that needs to be updatable. Therefore, my idea was to create an administration web application (let's call: Administration); both of which are virtual directories under a single website usually installed on Windows Server 2003 and used via the intranet.

    Periodically, the Application will make a web service call to see if there is a new version of the Application available. If there is an update available, the Application will not let the user use the Application until it has been updated.

    I was thinking that if an update was available an administrator would login to the Administration web app, download the update, from a remote site, and run a script (preferably a MSI) that would essentially shut down the Application and update the necessary files.

    I'm just unclear on a couple of things: 1.) How should I structure my solution (i.e. should I use the above schema but just add a Application web project and corresponding unit tests projects), 2.) For the updates, should I create a MSI of the updated Application that is downloaded and the Administration site essentially uninstalls and reinstalls the Application using a batch file that executes the uninstall and reinstall of the MSI, 3.) Is there a way to, using a single MSI, for the initial installation to create two virtual directories (one for each application, Administration and Application respectively) using a single Web Setup Project?

    I'm sorry if this seems kind of confusing. If something is, confusing, please let me know and I'll try to explain it to the best of my ability.

    Thank you in advance,
    Jim

    Tuesday, April 27, 2010 12:45 PM

Answers

  • User-952121411 posted

    Is there a way that I can roll up installing both the Administration and Application in a single Web Setup Project?
     

    I have not done this, but I think there should not be a problem.  When you right-click the web setup project, select Add -> Project Output -> and then just change the dropdown to the second project (say Admin app) and select ok after doing this for the 1st application.  You might need to custom configure where the files are dropped, etc, and I would deficiently recommend testing this 1st.  Once you get familiar with the configuration options in a web setup package you can customize things pretty easily.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2010 3:01 PM

All replies

  • User-952121411 posted

    I was thinking that if an update was available an administrator would login to the Administration web app, download the update, from a remote site, and run a script (preferably a MSI) that would essentially shut down the Application and update the necessary files.
     

    Actually, you should not have to worry about shutting down any existing instances.  If you create a web setup package using VS.NET, there is a property in the setup package properties that states: RemovePreviousVersions. Set this to True on your package.

    The next step is to change either the Version property and upon clicking off you will be prompted to generate a new Product Code automatically.  You can also change the Product Code manually if needed.  Do not change the Upgrade Code; this would require a full uninstall on the machine or server when the web app resides before installing the newer version.  If you only ever change the Version and Product Code the Admin that downloads your package will be able to execute the new .MSI and it will overwrite the old files without ever having to do a full uninstall or have any interruption to your end users.  This is all possible if you do not change the Upgrade Code; Windows uses this to determine it is an existing application to be overwritten with a newer version.

    Your idea of having an Admin app to look for an update seems reasonable.  You could incorporate this functionality directly in the app itself and make the call periodically in the background or whatever you want to do.  A lot of 'installed' apps work like this now; obviously you would not automate the download and install since it is a web app on IIS, but at least you could notify the users or Admin that a newer version exists.

    Here is a good tutorial on creating the web setup package if you have not done this before:

    Walkthrough: Deploying a Web Solution:

    http://msdn.microsoft.com/en-us/library/aa291424(VS.71).aspx

    Hope this helps! Smile

    Tuesday, April 27, 2010 4:11 PM
  • User-1209063919 posted

    Thanks much for the tip. I will give it a go today and let you know how it works. Is there a way that I can roll up installing both the Administration and Application in a single Web Setup Project?

    Wednesday, April 28, 2010 11:39 AM
  • User-952121411 posted

    Is there a way that I can roll up installing both the Administration and Application in a single Web Setup Project?
     

    I have not done this, but I think there should not be a problem.  When you right-click the web setup project, select Add -> Project Output -> and then just change the dropdown to the second project (say Admin app) and select ok after doing this for the 1st application.  You might need to custom configure where the files are dropped, etc, and I would deficiently recommend testing this 1st.  Once you get familiar with the configuration options in a web setup package you can customize things pretty easily.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2010 3:01 PM
  • User-1209063919 posted

    Yah, I still haven't been able to figure out the "creating 2 virtual directories in a single Web Server Project". Anyway, in this Application we are using a file-based SQL Server 2005 Express DB whose schema can change. Is there a way that I can change the database schema through the Web Setup Project. Even though they are under the same Solution, I'm not quite sure how to get the connection string to the Application's database. Then, when I have that, what's the best way to update the database? I was just thinking about writing a console application that consumes the update files/SQL scripts and executes them against the database. Any ideas?

    Wednesday, May 5, 2010 2:18 PM
  • User-1209063919 posted

    I changed things up a bit since I haven't been able to figure out how to create two virtual directories with a website project without having to invoke a lot of commandline scripts even though I have to to create an administrator user and add him to the local Administrator group. If worst comes to worst I can use the same pattern for a virtual directories. I was able to do the above but creating a Installer assembly and by overriding all of the Custom Actions, except for Commit, I am able to tap into the setup process and do some custom stuff.

    This is where I am at:

    During my setup I create a user and add him to the Administrators group on the server that my web application and SQLExpress 2005 instance is installed on.

    I'm trying to run a SMO script that lets the user select a SQLExpress instance, create the login (if it does not already exist), create the database (if it does not already exist). The script fails when it tries to create the login stating that I do not have the proper permissions, the same thing happens when I try to create the database without creating the login. I'm running under the assumption that the selected SQLExpress instance uses Windows authentication.

    In order to even get to this page, I have my web application set up to where only individuals of the Administrators group have access. I'm working under the assumption that since only an administrator can get to this page, the page is being executed under the Administrator group permissions. However, I think this is where my problem is. How can I get this to execute under that Administrator group permissions? I guess I don't know how to get ASP.net to execute the SMO script under a higher user than NETWORK SERVICE.

    Here is my code:


    Server server = new Server(DBInstanceName);
    bool dbFound = false;
    
    //search for database
    foreach (Microsoft.SqlServer.Management.Smo.Database db in server.Databases) {
        if (db.Name.ToLower() == DBName.ToLower()) {
            dbFound = true;
            break;
        }
    }
    
    //create database if not found
    if (!dbFound) {
        /*
         * MCTracker is the user that I create during the setup process overwriting the Install
         * Custom Action with my custom Installer class.
         */
        Microsoft.SqlServer.Management.Smo.Login log =
            new Microsoft.SqlServer.Management.Smo.Login(server,"MCTracker");
    
        //check for login
        bool loginFound = false;
        foreach (Microsoft.SqlServer.Management.Smo.Login l in server.Logins) {
            if (l.Name.ToLower() == log.Name.ToLower()) {
                loginFound = true;
                break;
            }
        }
    
        //create MCTracker login
        if (!loginFound) {
            log.LoginType = LoginType.WindowsUser;
            log.Create(); //FAILS HERE
            log.AddToRole("dbcreator");
        }
    
        //create database if not found
        if (!dbFound) {
            Microsoft.SqlServer.Management.Smo.Database DB =
                new Microsoft.SqlServer.Management.Smo.Database(server, DBName);
            DB.Create();
        }
    }
    



    Any ideas would be greatly appreciated. Thanks.

    Thursday, May 27, 2010 12:50 PM
  • User-952121411 posted

    I guess I don't know how to get ASP.net to execute the SMO script under a higher user than NETWORK SERVICE.

     

    You can use Impersonation pragmatically in code; I do it often to raise the authorization level for a block of code such as the one you presented.  Check out the following link which creates a token for a Windows User Account that you can then impersonate to run as an Administrator (includes full code example):

    WindowsImpersonationContext Class:

    http://msdn.microsoft.com/en-us/library/system.security.principal.windowsimpersonationcontext.aspx

    I would refactor the code for Impersonation into its own method or .dll for reusability so it doesn't clog up the actual code you have written, other than a few small calls for impersonation.

     

    Thursday, May 27, 2010 4:17 PM