diff --git a/src/Microsoft.Extensions.ApiDescription.Client/GetFileReferenceMetadata.cs b/src/Microsoft.Extensions.ApiDescription.Client/GetFileReferenceMetadata.cs
index 1241619418..54ae8b7500 100644
--- a/src/Microsoft.Extensions.ApiDescription.Client/GetFileReferenceMetadata.cs
+++ b/src/Microsoft.Extensions.ApiDescription.Client/GetFileReferenceMetadata.cs
@@ -15,23 +15,25 @@ namespace Microsoft.Extensions.ApiDescription.Client
///
public class GetFileReferenceMetadata : Task
{
+ private const string TypeScriptLanguageName = "TypeScript";
+
///
- /// Default Namespace metadata value for C# output.
+ /// Extension to use in default OutputPath metadata value. Ignored when generating TypeScript.
///
[Required]
- public string CSharpNamespace { get; set; }
+ public string Extension { get; set; }
+
+ ///
+ /// Default Namespace metadata value.
+ ///
+ [Required]
+ public string Namespace { get; set; }
///
/// Default directory for OutputPath values.
///
public string OutputDirectory { get; set; }
- ///
- /// Default Namespace metadata value for TypeScript output.
- ///
- [Required]
- public string TypeScriptNamespace { get; set; }
-
///
/// The ServiceFileReference items to update.
///
@@ -39,8 +41,7 @@ namespace Microsoft.Extensions.ApiDescription.Client
public ITaskItem[] Inputs { get; set; }
///
- /// The updated ServiceFileReference items. Will include Namespace and OutputPath metadata. OutputPath metadata
- /// will contain full paths.
+ /// The updated ServiceFileReference items. Will include ClassName, Namespace and OutputPath metadata.
///
[Output]
public ITaskItem[] Outputs{ get; set; }
@@ -50,6 +51,7 @@ namespace Microsoft.Extensions.ApiDescription.Client
{
var outputs = new List(Inputs.Length);
var destinations = new HashSet();
+
foreach (var item in Inputs)
{
var newItem = new TaskItem(item);
@@ -89,22 +91,24 @@ namespace Microsoft.Extensions.ApiDescription.Client
MetadataSerializer.SetMetadata(newItem, "ClassName", className);
}
- var isTypeScript = codeGenerator.EndsWith("TypeScript", StringComparison.OrdinalIgnoreCase);
var @namespace = item.GetMetadata("Namespace");
if (string.IsNullOrEmpty(@namespace))
{
- @namespace = isTypeScript ? CSharpNamespace : TypeScriptNamespace;
- MetadataSerializer.SetMetadata(newItem, "Namespace", @namespace);
+ MetadataSerializer.SetMetadata(newItem, "Namespace", Namespace);
}
var outputPath = item.GetMetadata("OutputPath");
if (string.IsNullOrEmpty(outputPath))
{
- outputPath = $"{className}{(isTypeScript ? ".ts" : ".cs")}";
+ var isTypeScript = codeGenerator.EndsWith(TypeScriptLanguageName, StringComparison.OrdinalIgnoreCase);
+ outputPath = $"{className}{(isTypeScript ? ".ts" : Extension)}";
}
- outputPath = GetFullPath(outputPath);
- MetadataSerializer.SetMetadata(newItem, "OutputPath", outputPath);
+ // Place output file in correct directory (relative to project directory).
+ if (!Path.IsPathRooted(outputPath) && !string.IsNullOrEmpty(OutputDirectory))
+ {
+ outputPath = Path.Combine(OutputDirectory, outputPath);
+ }
if (!destinations.Add(outputPath))
{
@@ -113,7 +117,10 @@ namespace Microsoft.Extensions.ApiDescription.Client
Log.LogError(Resources.FormatDuplicateFileOutputPaths(outputPath));
}
+ MetadataSerializer.SetMetadata(newItem, "OutputPath", outputPath);
+
// Add metadata which may be used as a property and passed to an inner build.
+ newItem.RemoveMetadata("SerializedMetadata");
newItem.SetMetadata("SerializedMetadata", MetadataSerializer.SerializeMetadata(newItem));
}
@@ -121,20 +128,5 @@ namespace Microsoft.Extensions.ApiDescription.Client
return !Log.HasLoggedErrors;
}
-
- private string GetFullPath(string path)
- {
- if (!Path.IsPathRooted(path))
- {
- if (!string.IsNullOrEmpty(OutputDirectory))
- {
- path = Path.Combine(OutputDirectory, path);
- }
-
- path = Path.GetFullPath(path);
- }
-
- return path;
- }
}
}
diff --git a/src/Microsoft.Extensions.ApiDescription.Client/build/Microsoft.Extensions.ApiDescription.Client.props b/src/Microsoft.Extensions.ApiDescription.Client/build/Microsoft.Extensions.ApiDescription.Client.props
index 2db402f022..d01b8044e8 100644
--- a/src/Microsoft.Extensions.ApiDescription.Client/build/Microsoft.Extensions.ApiDescription.Client.props
+++ b/src/Microsoft.Extensions.ApiDescription.Client/build/Microsoft.Extensions.ApiDescription.Client.props
@@ -12,7 +12,10 @@
-
+
true
@@ -28,10 +31,8 @@
Condition="'$(ServiceFileReferenceCheckIfNewer)' == ''">true
$([MSBuild]::EnsureTrailingSlash('$(ServiceFileReferenceDirectory)'))
- $(RootNamespace)
- $(RootNamespace)
+
+
-
+
Default
@@ -107,17 +111,20 @@
-
+
diff --git a/src/Microsoft.Extensions.ApiDescription.Client/build/Microsoft.Extensions.ApiDescription.Client.targets b/src/Microsoft.Extensions.ApiDescription.Client/build/Microsoft.Extensions.ApiDescription.Client.targets
index ecbac4412e..e7c60f9017 100644
--- a/src/Microsoft.Extensions.ApiDescription.Client/build/Microsoft.Extensions.ApiDescription.Client.targets
+++ b/src/Microsoft.Extensions.ApiDescription.Client/build/Microsoft.Extensions.ApiDescription.Client.targets
@@ -1,6 +1,6 @@
-
+
_ServiceProjectReferenceGenerator_GetTargetFramework;
@@ -25,8 +25,10 @@
-
-
+
@@ -45,14 +47,17 @@
-
+
<_TargetFrameworks>%(_Temporary.TargetFrameworks)
<_TargetFramework>$(_TargetFrameworks.Split(';')[0])
- $(_TargetFramework)
+ $(_TargetFramework)
<_Temporary Remove="@(_Temporary)" />
@@ -64,8 +69,11 @@
-
-
+
@@ -77,9 +85,6 @@
<_Temporary Remove="@(_Temporary)" />
-
+ Condition="'%(FullPath)' == '$(_FullPath)' AND '%(ProjectTargetFramework)' == '$(_TargetFramework)'">
$(_ProjectTargetPath)
<_Temporary Remove="@(_Temporary)" />
@@ -113,7 +118,8 @@
<_Temporary Remove="@(_Temporary)" />
-
+
@@ -124,9 +130,6 @@
<_Temporary Remove="@(_Temporary)" />
-
-
-
-
+
-
-
-
@@ -164,8 +165,9 @@
+ Condition="Exists('%(ServiceProjectReference.DocumentPath)')">
+ %(ServiceProjectReference.FullPath)
+
@@ -174,30 +176,36 @@
-
-
-
dotnet getdocument --no-build --project %(FullPath) --output %(DocumentPath)
$(DefaultDocumentGeneratorDefaultOptions)
+ $(Configuration)
-
+
%(Command) --framework %(ProjectTargetFramework)
- %(Command) --configuration $(Configuration)
- %(Command) --configuration %(ProjectConfiguration)
+
+
%(Command) --method %(Method)
+
+
%(Command) --service %(Service)
+
+
%(Command) --uri %(Uri)
- %(Command) %(DefaultDocumentGeneratorOptions)
+
+
+ %(Command) --configuration %(ProjectConfiguration) %(DefaultDocumentGeneratorOptions)
-
-
+
+
+
@@ -226,7 +234,9 @@
-
+
+ %(ServiceUriReference.Identity)
+
@@ -240,9 +250,9 @@
+ Extension="$(DefaultLanguageSourceExtension)"
+ Namespace="$(RootNamespace)"
+ OutputDirectory="$(ServiceFileReferenceDirectory)">
@@ -259,16 +269,14 @@
-
+
-
-
-
@@ -279,8 +287,43 @@
unique.
-->
-
-
+ <_Files Remove="@(_Files)" />
+ <_Files Include="@(ServiceFileReference -> '%(OutputPath)')"
+ Condition="$([System.IO.File]::Exists('%(ServiceFileReference.OutputPath)'))">
+ $([System.IO.Path]::GetExtension('%(ServiceFileReference.OutputPath)'))
+
+ <_Directories Remove="@(_Directories)" />
+ <_Directories Include="@(ServiceFileReference -> '%(OutputPath)')"
+ Condition="Exists('%(ServiceFileReference.OutputPath)') AND ! $([System.IO.File]::Exists('%(ServiceFileReference.OutputPath)'))" />
+
+
+
+
+ %(_Files.FullPath)
+
+
+
+
+ %(ServiceFileReference.FullPath)
+
+
+
+
+
+ %(_Directories.FullPath)
+
+
+
+
+ %(_Directories.FullPath)
+
+
+ <_Files Remove="@(_Files)" />
+ <_Directories Remove="@(_Directories)" />