Open adrien-constant opened 3 years ago
Hi, @adrien-constant Probably this issue is occured because the T4 template works only with OData v4 metadata.
Hi, @adrien-constant Probably this issue is occured because the T4 template works only with OData v4 metadata.
Thank you @unchase . What is the recommended way to automate the code generation for V2 metadata then ? I am using TextTransform.exe inside a Azure DevOps pipeline to generate C# files. If it's not possible to use T4 templates, is it possible to call directly the librairies with parameters to have the same behavior as using the extension inside VS ?
Hi @adrien-constant as @unchase has mentioned, the T4 templates only work with V4. Code generation for OData V1 to V3 are handled by a separate closed-source library. You can find documentation for it, but it was not meant for public use: EntityClassGenerator of the System.Data.Services.Design namespace.
To use this class you need to add references to the following assemblies to your project:
System.Data.Services.Design
System.Data.Entity
Note: I believe these are not available in .NET Core or .NET 5.
Here's an example of how you'd use it to generate code from a schema file:
// using System.Data.Services.Design;
var generator = new EntityClassGenerator(LanguageOption.GenerateCSharpCode)
{
Version = DataServiceCodeVersion.V2, // if you also want to support V3, check the notes below
UseDataServiceCollection = true // this adds supports for property binding by implementing INotifyPropertyChanged
};
using (var reader = XmlReader.Create("path\to\schema.xml"))
{
var errors = generator.GenerateCode(reader, "path\to\output\GeneratedCode.cs");
}
Notes: If for some reason you do not have access to the required assemblies, you could download the v3 assembly binaries that are located in the ODataConnectedService repo: https://github.com/OData/ODataConnectedService/tree/master/external/Binaries/V3
If you want to support V3, then you should definitely use these binaries as the built-in references seem to only support V1 and V2 (DataServiceCodeVersion.V3
is not available in the built-in assemblies).
@habbes Or we can modify the solution so that it has a separated command-line project (with all needed options) to run code generation for both OData V4 and OData V3 with using standart functionality in the Connected Service.
We can use, for example: commandline, or write your own command line parameter parser.
Hi @unchase, actually creating a cli tool is something we have considered https://github.com/OData/ODataConnectedService/issues/169 We don't yet have an ETA for it. @marabooy could you chime in.
@unchase I think creating the Cli version could be a great thing to have, Initially my thoughts for this would be to have a project that extracts the core codegeneration from the current connected service and have the new core be extensible/configurable by different frontends with the Vs extension being one of them and CLI being another and any other future projects.
@marabooy @habbes Do you think it is better to add the CLI project to the current solution or to move it out into a separate one? In the second case, it is necessary to move the common functionality into a separate library (for example, in nuget), and this can take a lot of time.
This is just my opinion, I do think we could have a new project in the solution the same way OData.net has 4 projects Edm, Spatial, Core & Client but with time we could extract the core library into a project that can be published to nuget if there are people who want to write their own frontends with the same. @habbes @gathogojr @ElizabethOkerio & @KenitoInc thoughts?
@unchase I think we can have a CLI project in the current solution. I don't think that contradicts the proposal made by @marabooy since the common functionality could also be a project in the same solution.
I'd suggest that the first path be to do the minimum refactoring required to have a standalone CLI project. Maybe we could even omit the file-splitting feature from this version of the CLI. Then in subsequent versions we also surface the core library that has no dependency on VS Shell.
But I think publishing the core library on NuGet should be done if there's demand for it or once we're sure its public API will be stable, because putting it on NuGet also means maintaining it, being conscious of breaking changes, etc.
Describe the bug
When using TextTransform.exe with a SAP OData V2 CSDL, there is an error. However, it works with the same XML file when the Connected Service is added within Visual Studio. The TextTransform.exe command also works with another OData V4 CSDL file.
Version of the Project affected
ODataConnectedService v1.2.0 VisualStudio Version v16.8.2 Microsoft.Odata.Client v7.6.3
To Reproduce
Steps to reproduce the behavior:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\TextTransform.exe" -P "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\Microsoft\ConnectedServices" -P "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\mstwd1cc.mrs" -P "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PublicAssemblies" "c:\temp\templates\ODataT4CodeGenerator.tt"
Expected behavior
Code is generated.
Actual behavior
Got an error :
CSDL File (test.xml)