The MediaTypeFormatter
has been compiled against the .NET Framework v4.0 to provide compatibility across a range of recent ASP.NET Web API releases. Developers can import it into your project either via NuGet or directly as an Assembly Reference, instructions are included for both below.
The MediaTypeFormatter
NuGet package uses David Ebbo's excellent WebActivator extension to inject startup behavior into your web application. This means other than installing the package you don't have do any additional work to be able to accept and emit YAML.
The following instructions apply to Visual Studio 2012+ it probably works for other versions of Visual Studio as long as you have the appropriate NuGet Package Manager extension and .NET Framework v4.0.
- Right Click on your Project, and select "Manage NuGet Packages...".
- Ensure "nuget.org" is selected in the Package Source drop down.
- Search for "YamlMediaTypeFormatter" and press .
- Depending on your configuration you may be asked to preview your changes, specifically you will be asked if you want to install
YamlDotNet
,WebActivatorEx
andYamlMediaTypeFormatter
.
The following instructions apply to Visual Studio 2012+ it probably works for other versions of Visual Studio as long as you have the appropriate NuGet Package Manager extension and .NET Framework v4.0.
-
From the Visual Studio Menu Bar, Select "Tools".
-
Select "NuGet Package Manager", then "Package Manager Console".
-
Ensure "nuget.org" is selected in the Package Source drop down.
-
Enter the following command in the console, replacing [YourProjectName] with the name of the project you wish to install the package into:
PM> Install-Package Amido.Net.Http.Formatting.YamlMediaTypeFormatter -ProjectName [YourProjectName]
If you do not want, or for some reason can not use NuGet or WebActivator then it is possible to install and use YamlMediaTypeFormatter
without either by compiling and referencing YamlMediaTypeFormatter
and YamlDotNet
directly.
As of the 1.0.0-PreRelease67 version compiled versions of YamlMediaTypeFormatter are released in a ZIP Archive on GitHub Releases this includes all of the DLLs, PDBs and XML files for YamlMediaTypeFormatter and it's dependencies.
Note: In the examples below, I use the HTTPS Git endpoints for each repository as these provide for the widest support. It is possible use SSH or Git protocols to clone the repositories although firewalls may interfere with their function.
To complete the following steps you will at a minimum need MSBuild 14 the easiest way to access this is by installing Visual Stuido 2015 RC or use a Pre-built Azure Image
-
Obtain the
YamlMediaTypeFormatter
solution source code, by cloning the Git repository into an appropriate location, such asC:\Source
:cd C:\Source git clone https://github.com/amido/YamlMediaTypeFormatter.git
-
From PowerShell execute the following command:
cd YamlMediaTypeFormatter ./build.ps1
-
After the build has completed browse to the following path in PowerShell or Windows Explorer:
Solutions\Amido.Net.Http.Formatting.YamlMediaTypeFormatter\bin\Release
-
Copy
Amido.Net.Http.Formatting.YamlMediaTypeFormatter.dll
to a location that you can reference from within your own project. -
Add a reference to
Amido.Net.Http.Formatting.YamlMediaTypeFormatter.dll
. -
Obtain the
YamlDotNet
solution source code, by cloning the Git repository into an appropriate location such asC:\Source
using PowerShell:cd C:\Source git clone https://github.com/aaubry/YamlDotNet.git
-
Change directory to
YamlDotNet
and execute the command to download and unblock NuGet.exe:cd YamlDotNet Invoke-WebRequest https://nuget.org/nuget.exe -OutFile nuget.exe Unblock-File nuget.exe
-
Restore NuGet packages:
& .\nuget.exe restore
-
Use MSBuild to compile the solution:
& "${ENV:ProgramFiles(x86)}\MSBuild\14.0\bin\MSBuild.exe" .\YamlDotNet.sln /p:configuration=Release-Signed
-
After the build has completed browse to the following path in PowerShell or Windows Explorer:
YamlDotNet\bin\Release-Signed
-
Copy
YamlDotNet.dll
to a location that you can reference from within your own project. -
Add a reference to
YamlDotNet.dll
. -
The
MediaTypeFormatter
will need to be registered with ASP.NET Web API, in yourWebApiConfig.cs
at the following code to theRegister
method:config.Formatters.Add(new YamlMediaTypeFormatter());
We welcome contributions from the community in the form of GitHub Pull Requests, you will need to use Visual Stuido 2015 as I use some of the syntactic sugar from C# 6.0. I would also suggest you use ReSharper 9.1 to maintain coding style through the project.