1+
2+ const core = require ( '@actions/core' ) ;
3+ const github = require ( '@actions/github' ) ;
4+
5+ try {
6+
7+ const fs = require ( 'fs' ) ;
8+
9+ const csproj = core . getInput ( 'csproj' ) ;
10+ const version = core . getInput ( 'version' ) ;
11+ const displayVersion = core . getInput ( 'displayVersion' ) ;
12+ const printFile = core . getInput ( 'printFile' ) ;
13+
14+
15+ // match <ApplicationVersion> followed by any sequence of characters that are not a '<', followed by </ApplicationVersion>
16+ const applicationVersionPattern = / < A p p l i c a t i o n V e r s i o n > [ ^ < ] * < \/ A p p l i c a t i o n V e r s i o n > / g;
17+ const applicationDisplayVersionPattern = / < A p p l i c a t i o n D i s p l a y V e r s i o n > [ ^ < ] * < \/ A p p l i c a t i o n D i s p l a y V e r s i o n > / g;
18+
19+ if ( version && version . trim ( ) !== '' ) {
20+ // Read the file contents
21+ var fileContents = fs . readFileSync ( csproj , 'utf8' ) ;
22+ var updatedApplicationVersion = fileContents . replace ( applicationVersionPattern , `<ApplicationVersion>${ version } </ApplicationVersion>` ) ;
23+ // Write the updated contents back to the file
24+ fs . writeFileSync ( csproj , updatedApplicationVersion , 'utf8' ) ;
25+ }
26+
27+ if ( displayVersion && displayVersion . trim ( ) !== '' ) {
28+ // Read the file contents
29+ var fileContents = fs . readFileSync ( csproj , 'utf8' ) ;
30+ var updatedApplicationVersion = fileContents . replace ( applicationDisplayVersionPattern , `<ApplicationDisplayVersion>${ displayVersion } </ApplicationDisplayVersion>` ) ;
31+ // Write the updated contents back to the file
32+ fs . writeFileSync ( csproj , updatedApplicationVersion , 'utf8' ) ;
33+ }
34+
35+ if ( printFile ) {
36+ var fileContents = fs . readFileSync ( csproj , 'utf8' ) ;
37+ console . log ( fileContents ) ;
38+ }
39+ }
40+ catch ( error ) {
41+ core . setFailed ( error . message ) ;
42+ }
0 commit comments