Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

CodeSmith refers to other files or .Net class libraries


May 25, 2021 CodeSmith


Table of contents


References to other files or .Net class libraries

The .Net class library can be referenced in the CodeSmith template, and different from a normal .Net project, references to the .Net library are implemented not through the Add reference of the project, but by indicating the Assembly to reference in the code template.

For example, by referencing CodeSmith's own CodeSmith.Custom .dll, you can use the following statement:

<%@ Assembly Name="CodeSmith.CustomProperties" %>
  • Name indicates the names of all assemblys that need to be referenced, or you can use the full name of Assembly, such as ExampleAssembly, Version=0.0.0,Culture=neutral, PublicKeyToken=null
  • Src indicates the relative path name of the source code that can be compiled dynamically
  • Path indicates the path that the app's Assembly holds

After referring to the appropriate Assembly, similar to the common C# language, for the .Net class used, you need to introduce the namespace in which the class resyse through Import.

CodeSmith, for example, uses Tutorial (9): The Progress object introduces System.Threading, where the Thread class is located

<%@ Import Namespace="System.Threading" %>

In addition, if you need to introduce some source code (such as some common code) into your code template, you can use include, for example:

<!– #include file="CommonScript.cs" –>

The method of sharing code, in addition to the include method used above, can also be implemented by setting the Src properties of CodeTemplate and Assembly.