mirror of
https://github.com/microsoft/mcp.git
synced 2026-11-04 12:01:31 +00:00
Add guidance to and standardize project reference patterns (#4036)
This commit is contained in:
1 parent
8701f6f2b7
commit
c3e9ec1093
19 files changed
+52
-33
No files matched your search
@@ -1934,7 +1934,7 @@ Live test projects must reference the server project and include specific proper
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Azure.Mcp.Tools.{Toolset}.csproj" />
|
<ProjectReference Include="..\..\src\Azure.Mcp.Tools.{Toolset}.csproj" />
|
||||||
<ProjectReference Include="..\..\..\..\servers\Azure.Mcp.Server\src\Azure.Mcp.Server.csproj" />
|
<ProjectReference Include="$(RepoRoot)servers\Azure.Mcp.Server\src\Azure.Mcp.Server.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Microsoft.Mcp.Core\src\Microsoft.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Microsoft.Mcp.Core\src\Microsoft.Mcp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Azure.Mcp.Core.csproj" />
|
<ProjectReference Include="..\..\src\Azure.Mcp.Core.csproj" />
|
||||||
<ProjectReference Include="..\Azure.Mcp.Tests\Azure.Mcp.Tests.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\tests\Azure.Mcp.Tests\Azure.Mcp.Tests.csproj" />
|
||||||
<ProjectReference Include="$(RepoRoot)servers\Azure.Mcp.Server\src\Azure.Mcp.Server.csproj" />
|
<ProjectReference Include="$(RepoRoot)servers\Azure.Mcp.Server\src\Azure.Mcp.Server.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Microsoft.Mcp.Core\src\Microsoft.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Microsoft.Mcp.Core\src\Microsoft.Mcp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -5,6 +5,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Microsoft.Mcp.Core\src\Microsoft.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Microsoft.Mcp.Core\src\Microsoft.Mcp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -230,3 +230,16 @@ The parameters in a server's `build.yml` decide what we produce. Set `PackageDoc
|
|||||||
|
|
||||||
## Project file properties
|
## Project file properties
|
||||||
Packaging and release scripts depend on metadata found in a build's build_info.json file, which is generated by `eng/scripts/New-BuildInfo.ps1` using properties from each server's project file. See [eng/scripts/Get-ProjectProperties.ps1](https://github.com/microsoft/mcp/blob/main/eng/scripts/Get-ProjectProperties.ps1) for a list of all supported project file properties.
|
Packaging and release scripts depend on metadata found in a build's build_info.json file, which is generated by `eng/scripts/New-BuildInfo.ps1` using properties from each server's project file. See [eng/scripts/Get-ProjectProperties.ps1](https://github.com/microsoft/mcp/blob/main/eng/scripts/Get-ProjectProperties.ps1) for a list of all supported project file properties.
|
||||||
|
|
||||||
|
### Project references
|
||||||
|
|
||||||
|
Use `$(RepoRoot)` for `ProjectReference` paths between components and for wildcard references. [Directory.Build.props](../Directory.Build.props) defines this property with a trailing directory separator, so do not add another separator after it or use `..` segments in rooted references.
|
||||||
|
|
||||||
|
Projects under a component's `tests` directory should reference that component's own `src` project using a relative path: `..\..\src\...` for projects nested under `tests\<project>`, or `..\src\...` for projects directly under `tests`. This includes test helpers and fixtures. References from tests to other components still use `$(RepoRoot)`.
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
||||||
|
<ProjectReference Include="$(RepoRoot)tools\Azure.*\src\*.csproj" />
|
||||||
|
```
|
||||||
|
|
||||||
|
The [project reference repair script](scripts/Fix-ProjectReferences.ps1) uses the same convention.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Fix Project References Script
|
# Fix Project References Script
|
||||||
# This script discovers all .csproj files, maps them by filename, and corrects all project references
|
# This script discovers all .csproj files, maps them by filename, and standardizes project references
|
||||||
|
|
||||||
Write-Host "Fixing project references in Azure MCP repository..." -ForegroundColor Green
|
Write-Host "Fixing project references in Azure MCP repository..." -ForegroundColor Green
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ $allCsprojFiles = Get-ChildItem -Path "." -Filter "*.csproj" -Recurse
|
|||||||
|
|
||||||
foreach ($file in $allCsprojFiles) {
|
foreach ($file in $allCsprojFiles) {
|
||||||
$filename = $file.Name
|
$filename = $file.Name
|
||||||
$relativePath = $file.FullName.Replace((Get-Location).Path + "\", "")
|
$relativePath = [System.IO.Path]::GetRelativePath((Get-Location).Path, $file.FullName).Replace('/', '\')
|
||||||
|
|
||||||
if ($projectMap.ContainsKey($filename)) {
|
if ($projectMap.ContainsKey($filename)) {
|
||||||
Write-Warning "Duplicate project file name found: $filename"
|
Write-Warning "Duplicate project file name found: $filename"
|
||||||
@@ -31,7 +31,13 @@ Write-Host "`nProcessing project files to fix references..." -ForegroundColor Ye
|
|||||||
$totalUpdated = 0
|
$totalUpdated = 0
|
||||||
|
|
||||||
foreach ($csprojFile in $allCsprojFiles) {
|
foreach ($csprojFile in $allCsprojFiles) {
|
||||||
Write-Host "`nProcessing: $($csprojFile.FullName.Replace((Get-Location).Path + '\', ''))" -ForegroundColor White
|
$relativeProjectPath = [System.IO.Path]::GetRelativePath((Get-Location).Path, $csprojFile.FullName).Replace('/', '\')
|
||||||
|
Write-Host "`nProcessing: $relativeProjectPath" -ForegroundColor White
|
||||||
|
|
||||||
|
$ownSourcePrefix = $null
|
||||||
|
if ($relativeProjectPath -match '^(.+)\\tests\\') {
|
||||||
|
$ownSourcePrefix = $Matches[1] + '\src\'
|
||||||
|
}
|
||||||
|
|
||||||
$content = Get-Content $csprojFile.FullName -Raw
|
$content = Get-Content $csprojFile.FullName -Raw
|
||||||
$updated = $false
|
$updated = $false
|
||||||
@@ -42,21 +48,21 @@ foreach ($csprojFile in $allCsprojFiles) {
|
|||||||
|
|
||||||
foreach ($match in $projectRefMatches) {
|
foreach ($match in $projectRefMatches) {
|
||||||
$currentPath = $match.Groups[1].Value
|
$currentPath = $match.Groups[1].Value
|
||||||
$referencedFileName = [System.IO.Path]::GetFileName($currentPath)
|
$referencedFileName = [System.IO.Path]::GetFileName($currentPath.Replace('\', '/'))
|
||||||
|
|
||||||
Write-Host " Found reference: $currentPath" -ForegroundColor Gray
|
Write-Host " Found reference: $currentPath" -ForegroundColor Gray
|
||||||
|
|
||||||
if ($projectMap.ContainsKey($referencedFileName)) {
|
if ($projectMap.ContainsKey($referencedFileName)) {
|
||||||
# Calculate the correct relative path from current file to referenced file
|
$relativeTargetPath = $projectMap[$referencedFileName]
|
||||||
$currentDir = [System.IO.Path]::GetDirectoryName($csprojFile.FullName)
|
$referencePath = '$(RepoRoot)' + $relativeTargetPath
|
||||||
$targetFullPath = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine((Get-Location).Path, $projectMap[$referencedFileName]))
|
if ($ownSourcePrefix -and $relativeTargetPath.StartsWith($ownSourcePrefix, [StringComparison]::OrdinalIgnoreCase)) {
|
||||||
|
$targetPath = Join-Path (Get-Location).Path $relativeTargetPath
|
||||||
|
$referencePath = [System.IO.Path]::GetRelativePath($csprojFile.DirectoryName, $targetPath).Replace('/', '\')
|
||||||
|
}
|
||||||
|
|
||||||
# Calculate relative path
|
if ($currentPath -ne $referencePath) {
|
||||||
$relativePath = [System.IO.Path]::GetRelativePath($currentDir, $targetFullPath)
|
Write-Host " Updating to: $referencePath" -ForegroundColor Green
|
||||||
|
$content = $content.Replace($currentPath, $referencePath)
|
||||||
if ($currentPath -ne $relativePath) {
|
|
||||||
Write-Host " Updating to: $relativePath" -ForegroundColor Green
|
|
||||||
$content = $content.Replace($currentPath, $relativePath)
|
|
||||||
$updated = $true
|
$updated = $true
|
||||||
} else {
|
} else {
|
||||||
Write-Host " Already correct" -ForegroundColor DarkGreen
|
Write-Host " Already correct" -ForegroundColor DarkGreen
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\McpToolEvaluator.Core\src\McpToolEvaluator.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)eng\tools\McpToolEvaluator.Core\src\McpToolEvaluator.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ModelContextProtocol" />
|
<PackageReference Include="ModelContextProtocol" />
|
||||||
<ProjectReference Include="..\..\McpToolEvaluator.Core\src\McpToolEvaluator.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)eng\tools\McpToolEvaluator.Core\src\McpToolEvaluator.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\McpToolEvaluator.Core\src\McpToolEvaluator.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)eng\tools\McpToolEvaluator.Core\src\McpToolEvaluator.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Azure.Mcp.Server.csproj" />
|
<ProjectReference Include="$(RepoRoot)servers\Azure.Mcp.Server\src\Azure.Mcp.Server.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -69,8 +69,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="$(RepoRoot)\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
||||||
<ProjectReference Include="$(RepoRoot)\tools\Azure.*\src\*.csproj" />
|
<ProjectReference Include="$(RepoRoot)tools\Azure.*\src\*.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -67,8 +67,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="$(RepoRoot)\core\Fabric.Mcp.Core\src\Fabric.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Fabric.Mcp.Core\src\Fabric.Mcp.Core.csproj" />
|
||||||
<ProjectReference Include="$(RepoRoot)\tools\Fabric.*\src\*.csproj" />
|
<ProjectReference Include="$(RepoRoot)tools\Fabric.*\src\*.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -67,8 +67,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="$(RepoRoot)\core\Template.Mcp.Core\src\Template.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Template.Mcp.Core\src\Template.Mcp.Core.csproj" />
|
||||||
<ProjectReference Include="$(RepoRoot)\areas\*\src\**\Template.*.csproj" />
|
<ProjectReference Include="$(RepoRoot)areas\*\src\**\Template.*.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<EmbeddedResource Include="**\Resources\*.json" />
|
<EmbeddedResource Include="**\Resources\*.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Azure.Core" />
|
<PackageReference Include="Azure.Core" />
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<EmbeddedResource Include="**\Resources\*.json" />
|
<EmbeddedResource Include="**\Resources\*.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Azure.ResourceManager" />
|
<PackageReference Include="Azure.ResourceManager" />
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<EmbeddedResource Include="**\Resources\*.json" />
|
<EmbeddedResource Include="**\Resources\*.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<IsAotCompatible>true</IsAotCompatible>
|
<IsAotCompatible>true</IsAotCompatible>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<EmbeddedResource Include="**\Resources\*.json" />
|
<EmbeddedResource Include="**\Resources\*.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
<ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in new issue
Block a user