Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

A simple example of how to instantiate and use Umbraco services (v7.7.6) in a standalone console application (.exe)

License

Notifications You must be signed in to change notification settings

madebybear/Umbraco-Console-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Umbraco-Console-App

A simple console application that makes use of Umbraco services within Umbraco 7.7.6.

Use Case

  • You have a custom Umbraco website that you've built. Using a windows scheduled task, you want run a umbraco console application and programmatically use the Umbraco Services to modify your content.

Prerequisites

  • Visual Studio 2015+
  • Intermediate knowledge of Umbraco Cms

Getting Started

  • Clone the repo to your machine
  • Open the .sln in Visual Studio, set the startup project to be My.Umbraco.Console
  • Build (F5) and ensure nuget packages are downloaded
  • The console should run and you'll see the root contents and children listed

Notes

My.Umbraco.Console - A simple Program.cs that will list the root / child nodes of My.Umbraco.Website.

Postbuild Events

In order for Umbraco to work, there is a a postbuild event that copies the .config files from My.Umbraco.Website to the current output folder e.g. /Debug/bin/config/*.config.

App.config

The app.config is actually a direct copy of the web.config that can be found in the root of My.Umbraco.Website (I manually copied the contents of the web.config into the app.config).

DataDirectory

When we override the GetBootManager there 2 lines that declare and set a data directory. This is when you're using connection string that includes |DataDirectory|. You should be able to remove/comment them out if you're using SQL Server and not an .SDF.

protected override IBootManager GetBootManager()
{
	var dataDirectory = new DirectoryInfo("..\\..\\..\\..\\src\\My.Umbraco.Website\\App_Data\\");
	AppDomain.CurrentDomain.SetData("DataDirectory", dataDirectory.FullName);

	return new ConsoleBootManager(this);
}

Even more postbuild events...

Finally, since my machine is x64 and this example is using an Sql CE .SDF for the Umbraco Database, I actually needed to copy the /bin/x86/ folder (that contains the x86 binaries for SQL Compact Edition) from My.Umbraco.Website so we don't get an error during startup that complains about File Version Mismatch between ADO.NET versions

My.Umbraco.Website

My.Umbraco.Website vanilla Umbraco 7.7.6 with the default starter package installed. To access the back office, open the .sln in Visual Studio and set the startup project to be My.Umbraco.Website, you can login with

Motivation

There are a some examples of how to use the Umbraco services inside a console app. However I needed an up-to-date example using the latest version of Umbraco 7.7.6. I need a quick simple example with minimal code to get started.

Acknowledgements

Built Using

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

A simple example of how to instantiate and use Umbraco services (v7.7.6) in a standalone console application (.exe)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published