I have the following scenario. I call a tool to generate code from data obtained via a rest service, like so:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<Target Name="Generate code" ...>
<Exec Command="dotnet tool run WebApiTool QueryUrl=https%3A%2F%2Fmy-web-api.azurewebsites.net%2Fapi%2Fv2%2Fexport%3Ftype%3Djson%26excludes%3DexcludeThis%2CexcludeThat" />
</Target>
</Project>
The URL is encoded, decoded it would look like this https://my-web-api.azurewebsites.net/api/v2/export?type=json&excludes=excludeThis,excludeThat
It is important, that the tool gets the ENCODED value, because WebApiTool is a legacy tool and it basically looks for the '=' character to parse commandline options.
My problem is that whenever I execute 'dotnet build', the encoded URL string gets automatically decoded before being passed to the WebApiTool.
Is there any way to prevent this?
You might want to also check out this.
You have several options to work around this issue:
Read the encoded URL from an external/separate file. So that it never appears in the project file as a literal string.
"Mask" the literal string in the project file.