Microsoft Visual Studio is the Integrated-Development Environment (IDE) for Microsoft Windows and .NET developments. Furthermore, since CodeFluent is based on the .NET platform and targets - for the moment - .NET and Microsoft platforms (SharePoint, SQL Server 2000/2005/2008, Excel, Windows Communication Foundation, etc.), combining Microsoft Visual Studio and CodeFluent in developments outcomes in creating an extremely productive environment, provided it is correctly done.
This article will guide you through the set up of your environment.
Pre-requisites
Before going any further in the tutorial, you need to have:
- A working Microsoft Visual Studio 2005 or 2008 installation,
- A working CodeFluent installation,
- Depending on the producers configured, make sure the targeted platforms are available and working (Microsoft SQL Server, IIS, etc.).
Creating your solution
The first step is to create your Visual Studio solution. Visual Studio must create new folders when creating new projects, and CodeFluent creates new folders if the output folder does not exist. Ergo, it's a good practice to create all projects prior to any CodeFluent generation in order to avoid any conflicts with Visual Studio later on.
Even though the solution name doesn't really matter, it's a good practice to create at least one containing all of your projects which will be a complete solution to work on your product. The good practice is usually to name that one after your product name. For instance, were we building a product named SampleFluent, this complete solution should be named SampleFluent as well. Afterwards, each team or developer can create its solution(s) containing only the needed projects.
To create a new solution, open Visual Studio, and go to File > New > Project... (CTRL+SHIFT+N), a project and solution name will be asked. The "New Project" dialog will appear, and you'll have to fill a project name, location and solution.
On the solution creation, a first project is asked.
Good practice is to name your Business Object Model (BOM) after your product, consequently it should match your solution name. Since by default Visual Studio uses typed-in project name as a solution name, by creating a Class Library which will contain your BOM and named after your product, it will type-in the solution name at the same time. Once done, click-on the OK button.
![]() |
Note: On the top right hand side of the window, it's possible to choose the targeted framework. Choose the one you desire and do not forget to configure CodeFluent so that it targets the same Framework. |
By now a solution with a single Class Library project was created. This project will be used as the BOM project.
the next steps are then to create a project for each targeted component of your application: a [ProductName].Design project which will contain the CodeFluent model, a [ProductName].Persistence which will contain your persistence related content, a [ProductName].WebSite which will reference the BOM project and contain your web site, and so on.
Creating the Design project
The first step is now to create a project which will contain the CodeFluent model. Even though not required it's good practice to have a project containing the CodeFluent model and all resources needed to generate your application (batch files, custom templates, custom patterns, etc.) so that developers can easily access the business model of the application, and that all those files can be easily included in the source control.
Good practice is to name it [ProductName].Design. For instance, to pursue with our SampleFluent example, the CodeFluent model should be designed in the SampleFluent.Design project. To do so click on your solution and in the contextual menu, click on Add > New Project...
Type-in the project's name and location and select the project type as a Class Library. The project type does not matter since this project won't be built by Visual Studio, it's just a project that acts as a container so that developer have an easy and integrated access to the model.
Create the model
Create your model parts in your project. Each model part is XML file named [ProductName].[PartName].xml.
It's good practice to create one pivot part named [ProductName].xml, that imports all other model parts. This is the model part that will be passed as a parameter to the CodeFluent.Build.exe tool later on, and that will be used to build your complete application.
Breaking down your model is up to you. Good practices are to split up entities into business (often equivalent to a namespace) parts (SampleFluent.Referential.xml, SampleFluent.Sales.xml, etc.) and into technical parts (SampleFluent.Producers.xml, SampleFluent.Resources.xml, SampleFluent.Instances.xml, etc.).
Create a batch file
Automate the generation of your application by creating a batch file to ensure the generation of your application is always launched properly. For instance here's a batch file generating our SampleFluent application:
| Generate.bat | Copy Code |
|---|---|
|
"%ProgramFiles%\SoftFluent\CodeFluent\Current\cfvars.bat" "%CF_CURRENT_PATH%\CodeFluent.Build.exe" SampleFluent.xml echo -- End -- | |
![]() |
Note: If CodeFluent environment variables are already set on your machine, you don't need to call the cfvars.bat file (CodeFluent Variables Script). Note: It's possible to pass parameters to your model by defining command line arguments as so: /[ParameterName]:[ParameterValue]. You'll then be able to use those parameters in your model by using its name surrounding by % as so: %[ParameterName]%. Refer to the CodeFluent.Build.exe help output for more information. |
You can then easily generate your application using a command prompt. Furthermore, if you're not a command prompt fan, it's possible to create in Visual Studio external commands and redirect their output in the output window. To do so navigate to Tools > External Tools... and point to your batch file with the required arguments if necessary.
Once the external tool created, you'll then even be able to create a button in Visual Studio by double clicking on an empty space among the toolbars, navigate to the Tool category and select your external command.
Finally, CodeFluent provides an out-of-the-box MsBuild task in the CodeFluent.Model assembly: this task can be used instead of the CodeFluent Builder tool to build a CodeFluent model.
More information on creating a Visual Studio external tool, and using the MsBuild task can be found in the following article: Industrializing the Production Process.
Include extra resources
Extra resources such as custom templates and patterns should be included for the same reasons as the model: an ease of access for developers, and to benefit from the source control.
Manage the generated files
When the batch file is launched, the Codefluent Builder tool (CodeFluent.Build.exe) will parse your model, create a meta-model from your model, and then each configured producers will produce platform specific code. When working with Visual Studio, what you want to do is too use CodeFluent to generate the files, but manage compilation with Visual Studio. To do so, each producers must be configured to not compile the generated output.
Then on each generation you'll have to include newly generated files, or remove the ones corresponding to suppressed entities.
![]() |
Note: An attribute named visualStudioProjectTargetPath on the producer configuration node exists; however not all producers support it. It indicates producers to update the defined Visual Studio project file with the generated files. |
Creating extra projects
Each producer produces platform specific code, ergo the project type to create depends on the producer type.
| Producer | Preferred Project Type | Preferred Name | Build Action | Description |
|---|---|---|---|---|
| Unrelevant | Class Library | [DefaultNamespace].Design | No | Contains the model and all resources required to generate the application. |
| Microsoft SQL Server Producer | SQL Server Project | [DefaultNamespace].Persistence | No | Contains T-SQL generated scripts used by CodeFluent to generate the database. |
| Business Object Model Producer | Class Library | [DefaultNamespace] | Yes | Contains the Business Object Model of your application. |
| Web Controls Producer | Class Library | [DefaultNamespace].Web | Yes | Contains the generated web controls that can be used in a web site. |
| Web Site Producer | Web Application | [DefaultNamespace].WebSite | Yes | Contains the generated web site. |
| Web Services 1.0 Producer (ASMX) | Web Service Application | [DefaultNamespace].Web.Services | Yes | Contains the generated web service ASMX files. |
| Service Object Model Producer (WCF) | Class Library | [DefaultNamespace].Proxy | Yes | Contains the remote object model that can be used by smart clients to consume the generated WCF services generated in the Business Object Model. |
| Microsoft Office Lists Producer | Web Application | [DefaultNamespace].Office.Web | Yes | This project should contain a web site which points to a generated web service |
Apart from the project type, the principle is just the same for each producer: use CodeFluent to generate the source files, use Visual Studio to develop and compile. Generated files should never be modified, since modifications would be lost at the next generation. Instead, one should modify the model and re-generate or extend generated classes through partial classes or add their own hand-made classes.
Configuring CodeFluent Producers
Once projects are configured, we need to configure our producers to generate the desired code in our project folders, so that afterwards we only have add them to our project in Visual Studio. First of all, we need to define our default namespace to our desired product name (SampleFluent in our case), and then set each targetDirectory attribute to their actual Visual Studio project directory.
Last step is to set the compile attribute to false for each producer since we want to compile with Visual Studio and not CodeFluent any more.
Here's the SampleFluent.Producers.xml part as an example:
| SampleFluent.Producers.xml | Copy Code |
|---|---|
|
<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1" defaultNamespace="SampleFluent" defaultKeyPropertyTypeName="int" defaultConnectionString="server=(local);database={1};Integrated Security=true"> <cf:producer name="Microsoft SQL Server Producer" typeName="CodeFluent.Producers.SqlServer.SqlServerProducer, CodeFluent.Producers.SqlServer"> <configuration targetDirectory="../{0}.Persistence"/> </cf:producer> <cf:producer name="Business Object Model Producer" typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom"> <configuration compile="false" outputName="bin\Debug\{0}.dll" runtimeResourceBaseName="{0}.{0}" resourceFileFormat="resx" targetDirectory="../{0}"> <subProducer name="LINQ To SQL Producer" typeName="CodeFluent.Producers.Linq.LinqMappingProducer, CodeFluent.Producers.Linq"/> <subProducer name="Service Object Model Producer" typeName="CodeFluent.Producers.ServiceModel.ServiceProducer, CodeFluent.Producers.ServiceModel" produceWebTypes="true" targetDirectory="..\{0}.Proxy" /> </configuration> </cf:producer> <cf:producer name="Template Producer" typeName="CodeFluent.Producers.CodeDom.TemplateProducer, CodeFluent.Producers.CodeDom"> <configuration sourceDirectory="Templates\ServiceModel" targetDirectory="..\{0}.IntegrationSamples"> </configuration> </cf:producer> <cf:producer name="Web Service 1.0 Producer" typeName="CodeFluent.Producers.CodeDom.UI.Web.WebServiceProducer, CodeFluent.Producers.CodeDom"> <configuration sourceDirectory="Templates\WebService" deploy="true" compile="false" webServiceTypes="Global" applicationName="{0}" targetBaseNamespace="{0}.Web.Services" targetDirectory="..\{0}.Web.Services" webServiceVirtualRootName="{0}.WS" webServicePhysicalRootPath="..\{0}.Web.Services\Site"/> </cf:producer> <cf:producer name="MS Office Lists Producer" typeName="CodeFluent.Producers.Office.ListProducer, CodeFluent.Producers.Office"> <configuration compile="false" targetDirectory="..\{0}.Office.Web" targetBaseNamespace="{0}.Office.Web" deploy="true" createVirtualRoot="false" webServiceVirtualRootName="{0}.Office" sourceDirectories="%CF_TEMPLATES_PATH%\OfficeWebService" webSiteSourceDirectories="%CF_TEMPLATES_PATH%\OfficeWebSite" webServicePhysicalRootPath="..\{0}.Office.Web" /> </cf:producer> <cf:producer name="Web Controls Producer" typeName="CodeFluent.Producers.CodeDom.UI.Web.WebControlsProducer, CodeFluent.Producers.CodeDom"> <configuration compile="false" targetDirectory="..\{0}.Web" targetBaseNamespace="{0}.Web" outputName="{0}.Web.dll"> <controlProducers> <controlProducer typeName="Grid" condition="BaseType.NodeType="Entity"" /> <controlProducer typeName="Form" condition="BaseType.NodeType="Entity"" /> <controlProducer typeName="ListBox" condition="BaseType.NodeType="Entity"" /> <controlProducer typeName="DropDownList" condition="BaseType.NodeType="Entity"" /> <controlProducer typeName="RadioButtonList" condition="BaseType.NodeType="Entity"" /> <controlProducer typeName="CheckBoxList" condition="BaseType.NodeType="Entity"" /> <controlProducer typeName="DataSource" condition="BaseType.NodeType="Entity"" /> <controlProducer typeName="Repeater" condition="BaseType.NodeType="Entity"" /> <controlProducer typeName="ListBox" condition="BaseType.NodeType="Enumeration"" /> <controlProducer typeName="DropDownList" condition="BaseType.NodeType="Enumeration" and BaseType.IsFlags=False" /> <controlProducer typeName="RadioButtonList" condition="BaseType.NodeType="Enumeration" and BaseType.IsFlags=False" /> <controlProducer typeName="CheckBoxList" condition="BaseType.NodeType="Enumeration" and BaseType.IsFlags=True" /> </controlProducers> </configuration> </cf:producer> <cf:producer name="Web Site Producer" typeName="CodeFluent.Producers.WebSite.WebSiteProducer, CodeFluent.Producers.WebSite"> <configuration sourceDirectory="Templates\WebSite" compile="false" targetDirectory="..\{0}.Web.Site" webSitePhysicalRootPath="..\{0}.Web.Site" webSiteVirtualRootName="{0}.Web"> </configuration> </cf:producer> </cf:project> | |
![]() |
Note: {0} stands for the default namespace defined in the project attribute. {1} in the defaultConnectionString attribute of the project node, stands for a database-friendly version of the default namespace. For instance, dots contained by the default namespace are replaced by underscores (e.g. FirstPart.SecondPart becomes FirstPart_SecondPart). The here-above producer part requires a Templates folder, in the SampleFluent.Design folder. This Templates folder must contain a:
|
For more information, please refer to the Tutorials section, where you'll find concrete use cases (such as The Persistence and the Business Layers or the The Persistence, the Business, and the Service Layers, etc.), that illustrate how to work with CodeFluent and Visual Studio.

