in sdk/dotnet/AzureML-Samples-CSharp/Assets/Component/ComponentOperations.cs [23:90]
public static async Task<MachineLearningComponentVersionResource> GetOrCreateComponentVersionAsync(
ArmClient armClient,
ResourceGroupResource resourceGroup,
string workspaceName,
string componentName,
string version,
string environmentId,
string codeArtifactId)
{
Console.WriteLine("Creating a ComponentVersion Resource...");
MachineLearningWorkspaceResource ws = await resourceGroup.GetMachineLearningWorkspaces().GetAsync(workspaceName);
string resourceId = $"{ws.Id}/components/{componentName}";
var id = new ResourceIdentifier(resourceId);
MachineLearningComponentContainerResource componentContainerResource = armClient.GetMachineLearningComponentContainerResource(id);
JObject jsonObject = JObject.Parse(@"{
'$schema': 'https://azuremlschemas.azureedge.net/latest/commandComponent.schema.json',
'name': '" + componentName + @"',
'type': 'command',
'version': '" + version + @"',
'code': 'azureml:/" + codeArtifactId + @"',
'command': 'echo Hello World & echo [${{inputs.component_in_number}}] & echo ${{inputs.component_in_path}} & echo ${{outputs.component_out_path}}',
'description': 'This is the basic command component',
'display_name': 'A basic Command Component',
'environment': 'azureml:" + environmentId + @"',
'inputs': {
'component_in_number': {
'default': '10.99',
'description': 'A number',
'optional': true,
'type': 'number'
},
'component_in_path': {
'description': 'A path',
'optional': false,
'type': 'path'
}
},
'outputs': {
'component_out_path': {
'name': 'component_out_path',
'type': 'path'
}
},
'is_deterministic': true,
'outputs': {
'component_out_path': {
'type': 'path'
}
},
'resources': {
'instance_count': 1
},
'tags': {
'owner': 'sdkteam',
'tag': 'tagvalue'
},
}");
MachineLearningComponentVersionProperties properties = new MachineLearningComponentVersionProperties { ComponentSpec = new BinaryData(jsonObject.ToString()) };
MachineLearningComponentVersionData data = new MachineLearningComponentVersionData(properties);
ArmOperation<MachineLearningComponentVersionResource> componentVersionResourceOperation = await componentContainerResource.GetMachineLearningComponentVersions().CreateOrUpdateAsync(WaitUntil.Completed, version, data);
MachineLearningComponentVersionResource componentVersionResource = componentVersionResourceOperation.Value;
Console.WriteLine($"ComponentVersionResource {componentVersionResource.Id} created.");
return componentVersionResource;
}