11import {
2- addProjectConfiguration , formatFiles , getWorkspaceLayout , names , NxJsonProjectConfiguration ,
3- ProjectConfiguration , ProjectType , Tree
2+ addProjectConfiguration ,
3+ formatFiles ,
4+ getWorkspaceLayout ,
5+ names ,
6+ NxJsonProjectConfiguration ,
7+ ProjectConfiguration ,
8+ ProjectType ,
9+ Tree ,
410} from '@nrwl/devkit' ;
511
612import { DotNetClient , dotnetNewOptions } from '@nx-dotnet/dotnet' ;
713import { findProjectFileInPath , isDryRun } from '@nx-dotnet/utils' ;
14+ import { readFileSync , writeFileSync } from 'fs' ;
15+ import { XmlDocument , XmlNode , XmlTextNode } from 'xmldoc' ;
16+ import { relative , dirname } from 'path' ;
817
918import {
10- GetBuildExecutorConfiguration , GetServeExecutorConfig , GetTestExecutorConfig ,
11- NxDotnetProjectGeneratorSchema
19+ GetBuildExecutorConfiguration ,
20+ GetServeExecutorConfig ,
21+ GetTestExecutorConfig ,
22+ NxDotnetProjectGeneratorSchema ,
1223} from '../../models' ;
1324import initSchematic from '../init/generator' ;
1425
@@ -71,7 +82,7 @@ async function GenerateTestProject(
7182 sourceRoot : `${ testRoot } ` ,
7283 targets : {
7384 build : GetBuildExecutorConfiguration ( testName ) ,
74- test : GetTestExecutorConfig ( )
85+ test : GetTestExecutorConfig ( ) ,
7586 } ,
7687 tags : schema . parsedTags ,
7788 } ) ;
@@ -98,16 +109,50 @@ async function GenerateTestProject(
98109 }
99110
100111 dotnetClient . new ( schema [ 'test-template' ] , newParams ) ;
101-
112+
102113 if ( ! isDryRun ( ) ) {
103114 const testCsProj = await findProjectFileInPath ( testRoot ) ;
115+ SetOutputPath ( host , testProjectName , testCsProj ) ;
104116 const baseCsProj = await findProjectFileInPath ( schema . projectRoot ) ;
117+ SetOutputPath ( host , schema . projectName , baseCsProj ) ;
105118 dotnetClient . addProjectReference ( testCsProj , baseCsProj ) ;
106- }
119+ }
120+ }
107121
122+ function SetOutputPath (
123+ host : Tree ,
124+ projectName : string ,
125+ projectFilePath : string
126+ ) : void {
127+ const xml : XmlDocument = new XmlDocument (
128+ readFileSync ( projectFilePath ) . toString ( )
129+ ) ;
130+
131+ const textNode : Partial < XmlTextNode > = {
132+ text : `${ relative ( dirname ( projectFilePath ) , process . cwd ( ) ) } \\dist\\${ projectName } ` ,
133+ type : 'text'
134+ } ;
135+ textNode . toString = ( ) => textNode . text ?? '' ;
136+ textNode . toStringWithIndent = ( ) => textNode . text ?? '' ;
137+
138+ const el : Partial < XmlNode > = {
139+ name : 'OutputPath' ,
140+ attr : { } ,
141+ type : 'element' ,
142+ children : [ textNode as XmlTextNode ] ,
143+ firstChild : null ,
144+ lastChild : null
145+ } ;
146+
147+ el . toStringWithIndent = xml . toStringWithIndent . bind ( el ) ;
148+ el . toString = xml . toString . bind ( el ) ;
149+
150+ xml . childNamed ( 'PropertyGroup' ) ?. children . push ( el as XmlNode ) ;
151+
152+ writeFileSync ( projectFilePath , xml . toString ( ) ) ;
108153}
109154
110- export async function GenerateProject (
155+ export async function GenerateProject (
111156 host : Tree ,
112157 options : NxDotnetProjectGeneratorSchema ,
113158 dotnetClient : DotNetClient ,
@@ -119,22 +164,29 @@ export async function GenerateProject (
119164
120165 const normalizedOptions = normalizeOptions ( host , options , projectType ) ;
121166
122- const projectConfiguration : ProjectConfiguration & NxJsonProjectConfiguration = {
167+ const projectConfiguration : ProjectConfiguration &
168+ NxJsonProjectConfiguration = {
123169 root : normalizedOptions . projectRoot ,
124170 projectType : projectType ,
125171 sourceRoot : `${ normalizedOptions . projectRoot } ` ,
126172 targets : {
127173 build : GetBuildExecutorConfiguration ( normalizedOptions . name ) ,
128- serve : GetServeExecutorConfig ( )
174+ serve : GetServeExecutorConfig ( ) ,
129175 } ,
130176 tags : normalizedOptions . parsedTags ,
131- }
177+ } ;
132178
133179 if ( options [ 'test-template' ] !== 'none' ) {
134- projectConfiguration . targets . test = GetTestExecutorConfig ( normalizedOptions . projectName + '-test' )
180+ projectConfiguration . targets . test = GetTestExecutorConfig (
181+ normalizedOptions . projectName + '-test'
182+ ) ;
135183 }
136184
137- addProjectConfiguration ( host , normalizedOptions . projectName , projectConfiguration ) ;
185+ addProjectConfiguration (
186+ host ,
187+ normalizedOptions . projectName ,
188+ projectConfiguration
189+ ) ;
138190
139191 const newParams : dotnetNewOptions = [
140192 {
@@ -160,7 +212,18 @@ export async function GenerateProject (
160212 dotnetClient . new ( normalizedOptions . template , newParams ) ;
161213
162214 if ( options [ 'test-template' ] !== 'none' ) {
163- await GenerateTestProject ( normalizedOptions , host , dotnetClient , projectType ) ;
215+ await GenerateTestProject (
216+ normalizedOptions ,
217+ host ,
218+ dotnetClient ,
219+ projectType
220+ ) ;
221+ } else {
222+ SetOutputPath (
223+ host ,
224+ normalizedOptions . projectName ,
225+ await findProjectFileInPath ( normalizedOptions . projectRoot )
226+ ) ;
164227 }
165228
166229 await formatFiles ( host ) ;
0 commit comments