Link to MSBuild built-in task speeds up brackets

I am writing an inline task for MSBuild. This requires a link to System.ServiceProcess.dll .

The task works fine if I hard-code the path to the System.ServiceProcess.dll file, for example:

 <UsingTask TaskName="MyTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> <Task> <Reference Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ServiceProcess.dll" /> <Code Type="Fragment" Language="cs">...working fine...</Code> </Task> </UsingTask> 

However, I would rather not hardcode this path.

If I just use <Reference Include="System.ServiceProcess.dll" /> , I get the error message: MSB3755: Could not find reference "System.ServiceProcess.dll" , so I think I need to use the full path here.

The $(FrameworkPathOverride) property already contains the correct path, so I tried using it:

 <Reference Include="$(FrameworkPathOverride)\System.ServiceProcess.dll" /> 

But this gives me an error:

C: \ path \ to \ project.csproj (93.3): error MSB3754: reference assembly "C: \ Program Files% 28x86% 29 \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.5 \ System.ServiceProcess. dll "is not valid. "The given assembly name or code base is invalid. (Exception from HRESULT: 0x80131047)" [C: \ path \ to \ project.csproj]

Notice how this slipped away (x86) at %28x86%29 .

It is noteworthy that this is done only for $(FrameworkPathOverride) . If I define my own property and use it instead, it works fine if this property also does not reference $(FrameworkPathOverride) . In other words, this works (but still has hard-coded paths):

 <PropertyGroup> <MyPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5</MyPath> </PropertyGroup> // (later, inside <Task />) <References Include="$(MyPath)\System.ServiceProcess.dll" /> 

However, this does not work with the same error that reports finding a path for %28x86%29 :

 <PropertyGroup> <MyPath>$(FrameworkPathOverride)</MyPath> </PropertyGroup> 

Just for the bumps, I also tried this option, which also fails with the same error:

 <PropertyGroup> <MyPath>$([System.Convert]::ToString("$(FrameworkPathOverride)"))</MyPath> </PropertyGroup> 

In addition, in all cases, the output of <Message Text="$(FrameworkPathOverride)" /> and <Message Test="$(MyPath)" /> is identical. The <Message /> task does not escape the bracket inside $(FrameworkPathOverride) , but there is <Reference Include="..." /> . Hm.

Why (x86) becomes %28x86%29 inside <Reference /> but not inside <Message /> ?

Why is this happening for $(FrameworkPathOverride) and not for $(MyPath) ?

Why does it start with $(MyPath) if it refers to $(FrameworkPathOverride) ?

How can I avoid hard coding this way?

+6
source share
1 answer

As in the previous attempt, have you tried using the Unbecape MSBuild property function?

 <PropertyGroup> <MyPath>$([MSBuild]::Unescape("$(FrameworkPathOverride)"))</MyPath> </PropertyGroup> 

This seems to be a known issue called "MSBuild 4.0 UsingTask cannot have a path with parentheses": http://connect.microsoft.com/VisualStudio/feedback/details/532677/msbuild-4-0-usingtask-cannot-have- a-path-with-parentheses

Unfortunately, I did not have the opportunity to verify this.

+5
source

Source: https://habr.com/ru/post/947132/


All Articles