Shrink Visual Studio 2017 project

I've created a visual studio 2017 with two webform projects in C#.  I've zipped it up and its over 40mb.  How do I make it smaller?  My actual code is only about 200 lines, but there are so many packages and scripts etc.  I'm working with C#, but am not sure if the same would apply to vb projects.
AlHal2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try remove the References that is not needed and try to recompile your solution and see if the size can be reduced?
0
AndyAinscowFreelance programmer / ConsultantCommented:
That sounds huge after zipping.
Do you have videos / pictures as part of the (web) projects ?
0
AlHal2Author Commented:
Here is my source code.  Can you suggest which references to remove.  I just removed optimisation and its affected Bundle.config.  Given that my program doesn't do any bundling, can I get rid of it?
Can I get rid of all the Microsoft.AI references for example?

<connectionStrings>
    <add name="TestConnectionString" connectionString="Data Source=.\SqlExpress;Initial Catalog=Zoos; Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="FrontEnd._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <asp:Label ID="Label1" runat="server" Text="Style" Width="50"></asp:Label>
    <asp:TextBox ID="txtStyle" runat="server"></asp:TextBox>
    <asp:Label ID="lblStyle" runat="server" Text=""></asp:Label>
    <p>
        <asp:Label ID="Label2" runat="server" Text="Colour" Width="50"></asp:Label>
        <asp:TextBox ID="txtColour" runat="server"></asp:TextBox>
        <asp:Label ID="lblColour" runat="server" Text=""></asp:Label>
    <p>
        <asp:Label ID="Label3" runat="server" Text="Sku" Width="50"></asp:Label>
        <asp:TextBox ID="txtSku" runat="server"></asp:TextBox>
        <asp:Label ID="lblSku" runat="server" Text=""></asp:Label>
    <p>
        <asp:Label ID="Label4" runat="server" Text="Title" Width="50"></asp:Label>
        <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
        <asp:Label ID="lblTitle" runat="server" Text=""></asp:Label>
<p>
    <asp:Label ID="Label5" runat="server" Text="Price" Width="50"></asp:Label>
    <asp:TextBox ID="txtPrice" runat="server"></asp:TextBox>
    <asp:Label ID="lblPrice" runat="server" Text=""></asp:Label>
</p>
    <asp:Label ID="Label6" runat="server" Text="Stock" Width="50"></asp:Label>
    <asp:TextBox ID="txtStock" runat="server"></asp:TextBox>
    <asp:Label ID="lblStock" runat="server" Text=""></asp:Label>
    <p>
        <asp:Button ID="cmdSave" runat="server" Text="Save" OnClick="cmdSave_Click" />
</asp:Content>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Database;
namespace FrontEnd
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void cmdSave_Click(object sender, EventArgs e)
        {
            lblStyle.Text = "";
            lblColour.Text = "";
            lblSku.Text = "";
            lblTitle.Text = "";
            lblPrice.Text = "";
            lblStock.Text = "";
            //Validate Data
            if (ValidateData(txtStyle.Text) == false)
            {
                lblStyle.Text = "Style must be alpha numeric";
                return;
            }
            if (ValidateData(txtColour.Text) == false)
            {
                lblColour.Text = "Colour must be alpha numeric";
                return;
            }
            if (ValidateData(txtSku.Text) == false)
            {
                lblSku.Text = "Sku must be alpha numeric";
                return;
            }
            if (ValidateData(txtTitle.Text) == false)
            {
                lblTitle.Text = "Title must be alpha numeric";
                return;
            }
            if (ValidateData(txtPrice.Text) == false)
            {
                lblPrice.Text = "Price must be alpha numeric";
                return;
            }
            if (ValidateData(txtStock.Text) == false)
            {
                lblStock.Text = "Stock must be alpha numeric";
                return;
            }
            SendToDatabase db = new SendToDatabase();
            db.SendToDb(txtStyle.Text, txtColour.Text, txtSku.Text, txtTitle.Text, txtPrice.Text, txtStock.Text);

        }
        public bool ValidateData(string Value)
        {

            System.Text.RegularExpressions.Regex emailRegex = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9.\\\\ .]+$");
            System.Text.RegularExpressions.Match emailMatch = emailRegex.Match(Value);
            return emailMatch.Success;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace Database
{
    public class SendToDatabase
    {
        public string SendToDb(string Style, string Colour, string Sku, string Title, string Price, string Stock)
        {
            using (SqlConnection sqlCon = new SqlConnection())
            {
                using (SqlCommand sqlcmd = new SqlCommand())
                {
                    try
                    {
                        string ConnectionString = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
                        sqlcmd.Connection = sqlCon;
                        sqlCon.ConnectionString = ConnectionString;
                        sqlCon.Open();
                        sqlcmd.CommandTimeout = 0;
                        sqlcmd.Parameters.Clear();
                        sqlcmd.CommandType = CommandType.Text;
                        sqlcmd.CommandText = "Insert into Products (Style,Colour,Sku,Title,Price,Stock)values('"+Style+"','"+Colour + "','" + Sku + "','" + Title + "','" + Price + "','" + Stock +"')";


                        sqlcmd.ExecuteNonQuery();

                        return "Fine";
                    }
                    catch (SqlException ex)
                    {
                        return "SQL Error. " + ex.Number + ": " + ex.Message;
                    }
                    catch (Exception ex)
                    {
                        return "Non SQL Error. " + ex.Message + ". Line = " + Convert.ToInt32(ex.StackTrace.Substring(ex.StackTrace.LastIndexOf(' ')));
                    }

                }
            }
        }
    }
}

Open in new window

0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
To remove a reference in Visual C#:
1. In Solution Explorer, open the References node under the project node.
2. Right-click a reference and click Remove.
0
Piotr StrycharzSoftware/web developerCommented:
Actually, references does make (almost) any difference - references just point to some assembly and even if not - assemblies are generally small. The thing that makes problem are packages.
Go to: Tools - NuGet Package Manager - Manager NuGet Packages for Solution. You will get the list of the installed packages. Select a package on the left, than select 'Project' checkbox on the right and press 'Uninstall button.
It will be a bit of fun with it because packages depend on each other (hint: start with '...optimization' packages).
Repeat uninstall step for all the (unneeded) packages.
Than - go to the bin folder of your project and remove everything from there (Visual Studio will recreate your dlls next time you build project). This will remove useless package assemblies.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlHal2Author Commented:
I removed some packages and got these error messages.  Which packages should I reinstall?

The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)    
The type or namespace name 'BundleCollection' could not be found (are you missing a using directive or an assembly reference?)
0
Piotr StrycharzSoftware/web developerCommented:
I would remove code that uses 'Optimization' and 'BundleCollection' types/namespaces (entire methods).
0
AlHal2Author Commented:
I deleted bundleconfig.cs from appstart directory in both projects.  The only error message now is
The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)  
from global.asax

I commented out using system.web.optimization and the line which runs bundleconfig.cs, but the error message remains.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;

namespace FrontEnd
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}

Open in new window

0
Piotr StrycharzSoftware/web developerCommented:
Comment also RouteConfig.RegisterRoutes line. Your Application_Start may look like this:

void Application_Start(object sender, EventArgs e)
{
	// Code that runs on application startup
	//RouteConfig.RegisterRoutes(RouteTable.Routes);
	//BundleConfig.RegisterBundles(BundleTable.Bundles);
}

Open in new window

0
AlHal2Author Commented:
Same error when I try to run or compile the project
The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;

namespace FrontEnd
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            //RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}

Open in new window

0
AlHal2Author Commented:
Found the problem.  Since I have 2 projects I needed to amend 2 global.asax files.
0
AlHal2Author Commented:
Thanks very much.
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>I've zipped it up and its over 40mb.  How do I make it smaller?

Out of interest just how much smaller does that make it?
0
AlHal2Author Commented:
I got rid of most of the nuget packages, but I wasn't sure if it was safe to get rid of all of them.
50% smaller.
Can I assume that if I'm not actively using any nuget packages they're not necessary by default eg a program with no code would compile if I removed all of them?
0
käµfm³d 👽Commented:
First, I wouldn't suggest getting rid of your NuGet packages because when you distribute that code to another person, they won't know which NuGet packages to install. You could instead delete the "packages" folder, which actually contains the DLL files that NuGet downloaded. DON'T delete the "packages.config" file from your project(s) because that is what keeps track of what NuGet packages are referenced in your project.

Second, I suggest doing a "clean" before you zip up your project. If you've built your project, and especially if you've built the project under different project configurations, then all of your DLLs that are referenced in your projects are output to the "bin" folder under each configuration that you've built under. For a DEBUG and a RELEASE configuration, this means you have two copies of all of the DLLs that are referenced. DLLs can be large. If you clean your solution, then all of the DEBUG and RELEASE folders' "bin" directories will be emptied. This means you won't have any DLLs in your zip file.
0
Piotr StrycharzSoftware/web developerCommented:
Your code will compile without any package if you do not use types from those packages. This is how webforms projects were working in previous versions of Visual Studio. Well, quite old versions - 2010 or earlier (2013 already adds unnecessary packages). My project with several dozen of pages took 2MB packed. Empty ASP.NET webform project on VS 2010 is 500kB unpacked.

Just use your navigation, scripts, etc - no need for the other person to install packages when project is being distributed.

The original question was about size. Well - small size vs convenience (smart URL, optimizations, scripts, CSS) = small size vs packages.
0
käµfm³d 👽Commented:
I wasn't clear in what I stated, I suppose. If your project is using anything from a particular NuGet package, then I would not suggest removing that NuGet package for the reason I mentioned above. If you are referencing a NuGet package, and you are sure you are not using anything from said package, then I agree with Piotr.

All NuGet is is a tool to distribute binaries and content files on a mass scale. Most NuGet  packages contain DLLs that offer some useful functionality to the consumer. So whereas your project may be referencing a NuGet package, and hence be referencing a DLL from that package, that doesn't mean that the package or the DLL is actively being used. The same can be said of doing a simple project reference within Visual Studio.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.