@@ -20,6 +20,9 @@ public class NewAzureProjectScaffolding : NewProjectScaffolding
20
20
private const string ParentDirectory = "../" ;
21
21
private const string SharedSourceLinkBase = "Shared/Core" ;
22
22
23
+ private int PathSegmentCount => _pathSegmentCount ??= GetPathSegmentCount ( ) ;
24
+ private int ? _pathSegmentCount ;
25
+
23
26
/// <inheritdoc/>
24
27
protected override string GetSourceProjectFileContent ( )
25
28
{
@@ -37,33 +40,9 @@ protected override string GetSourceProjectFileContent()
37
40
builder . PackageReferences . Add ( packages ) ;
38
41
}
39
42
40
- int pathSegmentCount = GetPathSegmentCount ( ) ;
41
- if ( AzureClientGenerator . Instance . InputLibrary . InputNamespace . Auth ? . ApiKey is not null )
42
- {
43
- builder . CompileIncludes . Add ( new CSharpProjectCompileInclude ( GetCompileInclude ( "AzureKeyCredentialPolicy.cs" , pathSegmentCount ) , SharedSourceLinkBase ) ) ;
44
- }
45
-
46
- bool hasOperation = false ;
47
- bool hasLongRunningOperation = false ;
48
- foreach ( var client in AzureClientGenerator . Instance . InputLibrary . InputNamespace . Clients )
49
- {
50
- TraverseInput ( client , ref hasOperation , ref hasLongRunningOperation ) ;
51
- }
52
-
53
- if ( hasOperation )
54
- {
55
- foreach ( var file in _operationSharedFiles )
56
- {
57
- builder . CompileIncludes . Add ( new CSharpProjectCompileInclude ( GetCompileInclude ( file , pathSegmentCount ) , SharedSourceLinkBase ) ) ;
58
- }
59
- }
60
-
61
- if ( hasLongRunningOperation )
43
+ foreach ( var compileInclude in BuildCompileIncludes ( ) )
62
44
{
63
- foreach ( var file in _lroSharedFiles )
64
- {
65
- builder . CompileIncludes . Add ( new CSharpProjectCompileInclude ( GetCompileInclude ( file , pathSegmentCount ) , SharedSourceLinkBase ) ) ;
66
- }
45
+ builder . CompileIncludes . Add ( compileInclude ) ;
67
46
}
68
47
69
48
return builder . Write ( ) ;
@@ -141,9 +120,58 @@ private static int GetPathSegmentCount()
141
120
return pathSegmentCount ;
142
121
}
143
122
144
- private string GetCompileInclude ( string fileName , int pathSegmentCount )
123
+ /// <summary>
124
+ /// Constructs a relative path for a compile include file based on the project structure.
125
+ /// </summary>
126
+ /// <param name="fileName">The name of the file to include.</param>
127
+ /// <param name="relativeSegment">The relative path segment to the shared source files (defaults to RelativeCoreSegment).</param>
128
+ /// <returns>A relative path string for the compile include file.</returns>
129
+ protected string GetCompileInclude ( string fileName , string relativeSegment = RelativeCoreSegment )
130
+ {
131
+ return $ "{ MSBuildThisFileDirectory } { string . Concat ( Enumerable . Repeat ( ParentDirectory , PathSegmentCount ) ) } { relativeSegment } { fileName } ";
132
+ }
133
+
134
+ /// <summary>
135
+ /// Gets the list of required CompileInclude files based on the project's requirements.
136
+ /// </summary>
137
+ /// <returns>A list of CSharpProjectCompileInclude files that should be included in the project.</returns>
138
+ protected override IReadOnlyList < CSharpProjectCompileInclude > BuildCompileIncludes ( )
145
139
{
146
- return $ "{ MSBuildThisFileDirectory } { string . Concat ( Enumerable . Repeat ( ParentDirectory , pathSegmentCount ) ) } { RelativeCoreSegment } { fileName } ";
140
+ var compileIncludes = new List < CSharpProjectCompileInclude > ( ) ;
141
+
142
+ // Add API key credential policy if API key authentication is configured
143
+ if ( AzureClientGenerator . Instance . InputLibrary . InputNamespace . Auth ? . ApiKey is not null )
144
+ {
145
+ compileIncludes . Add ( new CSharpProjectCompileInclude ( GetCompileInclude ( "AzureKeyCredentialPolicy.cs" ) , SharedSourceLinkBase ) ) ;
146
+ }
147
+
148
+ // Analyze clients to determine what shared files are needed
149
+ bool hasOperation = false ;
150
+ bool hasLongRunningOperation = false ;
151
+ foreach ( var client in AzureClientGenerator . Instance . InputLibrary . InputNamespace . Clients )
152
+ {
153
+ TraverseInput ( client , ref hasOperation , ref hasLongRunningOperation ) ;
154
+ }
155
+
156
+ // Add operation-related shared files if operations are present
157
+ if ( hasOperation )
158
+ {
159
+ foreach ( var file in _operationSharedFiles )
160
+ {
161
+ compileIncludes . Add ( new CSharpProjectCompileInclude ( GetCompileInclude ( file ) , SharedSourceLinkBase ) ) ;
162
+ }
163
+ }
164
+
165
+ // Add long-running operation shared files if LRO operations are present
166
+ if ( hasLongRunningOperation )
167
+ {
168
+ foreach ( var file in _lroSharedFiles )
169
+ {
170
+ compileIncludes . Add ( new CSharpProjectCompileInclude ( GetCompileInclude ( file ) , SharedSourceLinkBase ) ) ;
171
+ }
172
+ }
173
+
174
+ return compileIncludes ;
147
175
}
148
176
}
149
177
}
0 commit comments