I've come up with a workaround for this issue, although it's not ideal and I would be grateful for a better solution.
One approach is to use custom config file names with the tsc
command, but it requires specific adjustments within MSBuild by including
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
in the project file along with additional configurations to execute it.
MSBuild allows for different settings between Release and Debug modes, but only if it controls all TypeScript configurations and there are no instances of tsconfig.json
files within the project structure.
While MSBuild can locate any tsconfig.json
file at any level of folder depth, alternative file names such as tsconfig.release.json
or tsconfig.debug.json
cannot be identified.
Furthermore, MSBuild has the ability to adjust inclusion rules for files, leading to the following solution:
- Reposition the release overrides to a designated folder so that
tsconfig.release.json
becomes releaseConfig/tsconfig.json
. This will necessitate adjustments to relative paths in order to locate the project:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"sourceMap": false,
"removeComments": true
},
"include": [ "../**/*" ]
}
- Two modifications are required in the
.csproj
file. Firstly, prevent this configuration from being utilized in non-release builds:
<ItemGroup Condition="'$(Configuration)|$(Platform)'!='Release|AnyCPU'">
<Content Remove="whatever\releaseConfig\tsconfig.json" />
<None Include="whatever\releaseConfig\tsconfig.json" />
</ItemGroup>
- Lastly, for the release build, switch the file references:
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Content Remove="whatever\tsconfig.json" />
<None Include="whatever\tsconfig.json" />
<None Remove="whatever\releaseConfig\tsconfig.json" />
</ItemGroup>
The default tsconfig.json
is taken out of <Content>
, but must be included under <None>
to maintain the appropriate relative paths in releaseConfig\tsconfig.json
.