title: User Controls (asp.net, ascx-files) inside a C# class library, build error (aspnet_compiler.exe)
body: <p>Having trouble "passing" this error from ASPNET_Compiler.exe:</p>
  
  <p><em>error CS0103: The name 'TestMath' does not exist in the current context.</em></p>
  
  <p>The function called within TestMath from a user control (.cs) file, is outside of the context (scope/namespace/...). If I comment out the line that calls a method within TestMath the compilation works and so does my user control (referenced the DLL from within a WebApplication).</p>
  
  <p>The "TestMath"-class is a static class which contains one static method "Get", which returns -1+3 (I have also tried creating it non-static... without luck).</p>
  
  <p>The normal build in Visual Studio (MSBuild) works, but as we all know; it does not pack .ascx files into the DLL properly.</p>
  
  <p>I've attached a .rar containing:</p>
  
  <ol>
  <li>TestLibrary </li>
  </ol>
  
  <p>Contains 1 .ascx control and 1 math class</p>
  
  <p>Contains a post-build event, that runs the "BuildAssembly.cmd", which in turn runs aspnet_compiler and aspnet_merge.</p>
  
  <ol start="2">
  <li>WebSite - one .aspx page, to display the control from the library.</li>
  </ol>
  
  <p>The line that gives the error is located inside Label.ascx.cs, line 18:</p>
  
  <pre><code>Lbl.Text += " MATH: " + TestMath.Get()
  </code></pre>
  
  <p>Any suggestions at all? Take a guess? Calling a method in a class outside of the .ascx.cs is prohibited? Oh... But there's something to those words! Which mean; if I copy the Math-class inside the User-Control class, like so:</p>
  
  <pre><code>public class Label : UserControl
  {
      ..methods of label
      public class Math
      { 
        public static Get()
      }
  }
  </code></pre>
  
  <p>The solution does compile and I am able to call methods within both classes... But, as we all want; I am no different: I want to also be able to call other objects (which I do already, they just live in GAC...)... so, hm... Basically; where does aspnet_compiler look for dll's...</p>
  
  <p>Download example solution:
  <a href="http://s000.tinyupload.com/?file_id=76690332418132532036" rel="nofollow">http://s000.tinyupload.com/?file_id=76690332418132532036</a></p>
  
  <p><em>If you un-pack the solution to C:\Solutions\Test, you can run it with little to no hassle, assuming Visual Studio 2010, Windows 7... .NET framwork 4 or higher.</em></p>
  
  <p>Else, here's some code:
  ASCX</p>
  
  <pre><code>&lt;%@ Control Language="C#" 
  AutoEventWireup="true" 
  ClassName="TestLibrary.Controls.Label"
  CodeFile="Label.ascx.cs"
  CodeBehind="Label.ascx.cs"
  Inherits="TestLibrary.Controls.LabelCode" %&gt;
  
  
  
  Test
  
   &lt;asp:Label runat="server" ID="Lbl"&gt;&lt;/asp:Label&gt;
  </code></pre>
  
  <p>ASCX code behind</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          Lbl.Text = "CodeBehindText...";
          Lbl.Text += " MATH: " + TestMath.Get();
      }
  </code></pre>
  
  <p>TestMath</p>
  
  <pre><code> public static int Get()
      {
          return -1 + 3;
      }
  </code></pre>
  
  <p>BuildAssembly.cmd</p>
  
  <pre><code>SET compiler_path=%systemroot%\Microsoft.NET\Framework64\v4.0.30319
  SET aspnet_merge=C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\aspnet_merge.exe
  SET websiteproject=C:\Solutions\Test\TestLibrary\TestLibrary
  SET compiled=C:\Solutions\Test\TestLibrary\TestLibrary\Compiled
  SET outputfolder=C:\Solutions\Test\TestLibrary\TestLibrary\bin\Release
  SET outputfilenamedll=TestLibrary.dll
  %compiler_path%\aspnet_compiler.exe -p "%websiteproject%" -c -f -d -v / %compiled%
  "%aspnet_merge%" %compiled% -o %outputfilenamedll%
  COPY /Y %compiled%\bin\%outputfilenamedll% %outputfolder%\%outputfilenamedll%
  RMDIR /s /q %compiled%
  </code></pre>
  
  <p>Wondering why all this "fuzz" with ASCX in 2015? Oh, hoped to reuse ascx files created several years ago, packing them in a library for eternity, signing the assembly, import it to my SharePoint-environment... </p>