Если ваша структура папок выглядит примерно так:
1. * Azure Репопы Devops содержат папку решения (где существует файл xx.sln).
2. И эти проекты находятся в той же папке решения.
Вы можете попробовать мой скрипт:
<PropertyGroup>
<ProjectFolder>$([System.IO.Directory]::GetParent($(ProjectDir)))</ProjectFolder>
<MySolutionDir>$([System.IO.Directory]::GetParent($(ProjectFolder)))\</MySolutionDir>
</PropertyGroup>
$(MySolutionDir)
представляет путь, в котором существуют ваши файлы sln и папки проекта. Так же, как $(SolutionDir)
, он также имеет \
. Таким образом, его формат выглядит как SomePath\
.
И рекомендуется , чтобы вставить мой сценарий выше сценария события PreBuild. Что-то вроде:
<PropertyGroup>
<ProjectFolder>$([System.IO.Directory]::GetParent($(ProjectDir)))</ProjectFolder>
<MySolutionDir>$([System.IO.Directory]::GetParent($(ProjectFolder)))\</MySolutionDir>
It's recommended to add my script and PreBuildEvent in same propertyGroup, and mine should be in the first.
<PreBuildEvent>echo $(MySolutionDir)</PreBuildEvent>
</PropertyGroup>
Edit1:
Вы также можете добавить условие:
<PropertyGroup>
<ProjectFolder>$([System.IO.Directory]::GetParent($(ProjectDir)))</ProjectFolder>
<MySolutionDir>$([System.IO.Directory]::GetParent($(ProjectFolder)))\</MySolutionDir>
<SolutionDir Condition="xxxx">$(MySolutionDir)</SolutionDir>
It's recommended to add my script and PreBuildEvent in same propertyGroup, and mine should be in the first.
<PreBuildEvent>echo $(MySolutionDir)</PreBuildEvent>
</PropertyGroup>
Edit2:
Хм, теперь я могу воспроизвести проблему на моей стороне. Это довольно странное поведение, и я не уверен насчет root причины этого. Но быстрый обходной путь - это создать новый PropertyGroup
для вставки нашего пользовательского скрипта вместо его вставки в существующий PropertyGroup
из шаблона по умолчанию:
Раньше это было:
....
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
<!-- Default to the v11.0 targets path if the targets file for the current VS version is not found -->
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">11.0</VisualStudioVersion>
<ProjectFolder>$([System.IO.Directory]::GetParent($'(ProjectDir)'))</ProjectFolder>
<ParentFolder>$([System.IO.Directory]::GetParent($'(ProjectFolder)'))\</ParentFolder>
<SolutionDir Condition=" '$(SolutionDir)' == '' Or '$(SolutionDir)' == '*Undefined*' ">$(ParentFolder)</SolutionDir>
<PreBuildEvent>echo $(SolutionDir)</PreBuildEvent>
</PropertyGroup>
<Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
<Import Condition="'$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
<ItemGroup>
<Folder Include="Properties" />
</ItemGroup>
<ItemGroup>
<Build Include="test.sql" />
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>echo $(SolutionDir)</PreBuildEvent>
</PropertyGroup>
</Project>
Сейчас измените его на:
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
<!-- Default to the v11.0 targets path if the targets file for the current VS version is not found -->
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">11.0</VisualStudioVersion>
</PropertyGroup>
<Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
<Import Condition="'$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
<ItemGroup>
<Folder Include="Properties" />
</ItemGroup>
<ItemGroup>
<Build Include="test.sql" />
</ItemGroup>
<PropertyGroup>
<ProjectFolder>$([System.IO.Directory]::GetParent($(ProjectDir)))</ProjectFolder>
<ParentFolder>$([System.IO.Directory]::GetParent($(ProjectFolder)))\</ParentFolder>
<SolutionDir Condition=" '$(SolutionDir)' == '' Or '$(SolutionDir)' == '*Undefined*' ">$(ParentFolder)</SolutionDir>
<PreBuildEvent>echo $(SolutionDir)</PreBuildEvent>
</PropertyGroup>
Также удалите лишние '
в $(ProjectDir)
. Это должно быть $(ProjectDir)
вместо $'(ProjectDir)'
и $'(ProjectFolder)'
. Я также вижу, что у вас есть два свойства PreBuildEvent
, просто оставьте одно в нашем собственном скрипте. После вышеуказанных шагов ваш проект теперь хорошо работает на моей стороне: