Una vez más estoy luchando contra MSBuild. Quiero tener un valor de propiedad definido con una ruta raíz. Como parte de la compilación, la ruta se actualizará con la información de la versión. Sin embargo, MSBuild parece tener sus propias reglas de alcance que parecen completamente al revés. Tome este primer ejemplo:MSBuild Propiedad Scope
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<MyPath>\\server\folder</MyPath>
</PropertyGroup>
<Target Name="Main">
<Message Text="In Main Before - MyPath = $(MyPath)"/>
<CallTarget Targets="Task1" />
<CallTarget Targets="Task2" />
<CallTarget Targets="Task3" />
<Message Text="In Main After - MyPath = $(MyPath)"/>
</Target>
<Target Name="Task1">
<PropertyGroup>
<MyPath>$(MyPath)\version5</MyPath>
</PropertyGroup>
<Message Text="In Task1 - MyPath = $(MyPath)"/>
</Target>
<Target Name="Task2">
<Message Text="In Task2 - MyPath = $(MyPath)"/>
</Target>
<Target Name="Task3">
<Message Text="In Task3 - MyPath = $(MyPath)"/>
</Target>
</Project>
Aquí está la salida con esta línea de comandos: msbuild PropertyScopeTest1.proj /target:Main
Project "C:\Temp\PropertyScopeTest1.proj" on node 1 (Main target(s)).
Main:
In Main Before - MyPath = \\server\folder
Task1:
In Task1 - MyPath = \\server\folder\version5
Task2:
In Task2 - MyPath = \\server\folder\version5
Task3:
In Task3 - MyPath = \\server\folder\version5
Main:
In Main After - MyPath = \\server\folder
Done Building Project "C:\Temp\PropertyScopeTest1.proj" (Main target(s)).
Ahora, aquí es una versión ligeramente diferente estableciendo la variable de MyPath en el objetivo principal:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<MyPath>\\server\path</MyPath>
</PropertyGroup>
<Target Name="Main">
<Message Text="In Main Before - MyPath = $(MyPath)"/>
<PropertyGroup>
<MyPath>$(MyPath)\version5</MyPath>
</PropertyGroup>
<Message Text="In Main After PropertyGroup - MyPath = $(MyPath)"/>
<CallTarget Targets="Task1" />
<CallTarget Targets="Task2" />
<CallTarget Targets="Task3" />
<Message Text="In Main After - MyPath = $(MyPath)"/>
</Target>
<Target Name="Task1">
<Message Text="In Task1 - MyPath = $(MyPath)"/>
</Target>
<Target Name="Task2">
<Message Text="In Task2 - MyPath = $(MyPath)"/>
</Target>
<Target Name="Task3">
<Message Text="In Task3 - MyPath = $(MyPath)"/>
</Target>
</Project>
Aquí está la salida con esta línea de comando: msbuild PropertyScopeTest2.proj /target:Main
Project "C:\Temp\PropertyScopeTest2.proj" on node 1 (Main target(s)).
Main:
In Main Before - MyPath = \\server\path
In Main After PropertyGroup - MyPath = \\server\path\version5
Task1:
In Task1 - MyPath = \\server\path
Task2:
In Task2 - MyPath = \\server\path
Task3:
In Task3 - MyPath = \\server\path
Main:
In Main After - MyPath = \\server\path\version5
Done Building Project "C:\Temp\PropertyScopeTest2.proj" (Main target(s)).
He visto otros enlaces en este sitio que son similares, pero todos parecen llamar a la tarea MSBuild desde el archivo del proyecto MSBuild. Todo lo que quiero hacer es actualizar la ruta y tenerla disponible en todas partes del proyecto. ¿Algunas ideas?
Esta solución tiene mucho más sentido para mí. Planeo probar esto mañana y ver si funcionará para mi caso de uso. – dprice
Acabo de probar esta solución y es exactamente lo que quería. ¡Muchas gracias! – dprice