Skip to content

Commit be5597d

Browse files
authored
Better codegen: fix .props .targets & bundled packaging #42
2 parents b90b1f3 + 0b82af6 commit be5597d

11 files changed

Lines changed: 131 additions & 82 deletions

File tree

src/CodegenTests/CodegenTests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@
1717

1818
<Import Project="$(MSBuildProjectDirectory)\..\Rcl.NET\build\Rcl.NET.targets" />
1919
<Import Project="$(MSBuildProjectDirectory)\..\Rcl.NET\build\Rcl.NET.props" />
20-
<Import Project="$(MSBuildProjectDirectory)\..\Rcl.NET\build\ros2cs.targets" />
2120
</Project>

src/Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
<Copyright>Copyright (c) 2022-2025, noelex@outlook.jp</Copyright>
1313
<PackageTags>ros, ros2, rcl, rosidl, ros2cs, rclnet</PackageTags>
1414
<SignAssembly>true</SignAssembly>
15-
<AssemblyOriginatorKeyFile>$(ProjectDir)..\SigningKey.snk</AssemblyOriginatorKeyFile>
15+
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\SigningKey.snk</AssemblyOriginatorKeyFile>
1616
<PublicSign>True</PublicSign>
1717
</PropertyGroup>
18-
<ItemGroup >
19-
<None Include="$(ProjectDir)..\..\README.md" Pack="True" PackagePath="\" Visible="False" />
20-
<None Include="$(ProjectDir)..\..\LICENSE" Pack="True" PackagePath="\" Visible="False" />
18+
<ItemGroup>
19+
<None Include="$(MSBuildThisFileDirectory)..\README.md" Pack="True" PackagePath="\" Visible="False" />
20+
<None Include="$(MSBuildThisFileDirectory)..\LICENSE" Pack="True" PackagePath="\" Visible="False" />
2121
</ItemGroup>
2222
</Project>

src/Directory.Build.targets

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<PropertyGroup>
4+
<GetRos2csPropsDependsOn>
5+
$(GetRos2csPropsDependsOn);Get_ros2cs
6+
</GetRos2csPropsDependsOn>
7+
</PropertyGroup>
8+
9+
<Target Name="Get_ros2cs">
10+
<MSBuild Projects="$(MSBuildThisFileDirectory)\ros2cs\ros2cs.csproj"
11+
Targets="Restore"
12+
RemoveProperties="TargetFramework"
13+
/>
14+
15+
<MSBuild Projects="$(MSBuildThisFileDirectory)\ros2cs\ros2cs.csproj"
16+
Targets="Publish"
17+
Properties="Configuration=$(Configuration);TargetFramework=$(Ros2csBundleTfm);Version=$(Version)"
18+
/>
19+
20+
<PropertyGroup>
21+
<Ros2csDir>$(MSBuildThisFileDirectory)\ros2cs\bin\$(Configuration)\$(Ros2csBundleTfm)\publish</Ros2csDir>
22+
<Ros2csExe>&quot;$(Ros2csDir)\ros2cs.dll&quot;</Ros2csExe>
23+
</PropertyGroup>
24+
25+
<Message Text="[$(MSBuildProjectName), Source Build] Using ros2cs from $(Ros2csExe)"/>
26+
</Target>
27+
28+
</Project>

src/Rcl.NET.Tests/Rcl.NET.Tests.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -28,11 +28,13 @@
2828
<ProjectReference Include="..\Rcl.NET\Rcl.NET.csproj" />
2929
</ItemGroup>
3030

31+
<Import Project="..\Rcl.NET\build\Rcl.NET.props"/>
32+
<Import Project="..\Rcl.NET\build\Rcl.NET.targets"/>
33+
34+
<!-- ../Directory.Build.props & .targets are also imported to gather the source ros2cs -->
35+
3136
<ItemGroup>
3237
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
3338
</ItemGroup>
3439

35-
<Import Project="$(MSBuildProjectDirectory)\..\Rcl.NET\build\Rcl.NET.targets" />
36-
<Import Project="$(MSBuildProjectDirectory)\..\Rcl.NET\build\Rcl.NET.props" />
37-
<Import Project="$(MSBuildProjectDirectory)\..\Rcl.NET\build\ros2cs.targets" />
3840
</Project>

src/Rcl.NET/Rcl.NET.csproj

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -43,29 +43,26 @@
4343
<ItemGroup>
4444
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.1.2" />
4545
</ItemGroup>
46+
47+
<ItemGroup>
48+
<ProjectReference Include="..\Rosidl.Runtime\Rosidl.Runtime.csproj" />
49+
</ItemGroup>
4650

47-
<ItemGroup>
48-
<ProjectReference Include="..\Rosidl.Runtime\Rosidl.Runtime.csproj" />
49-
</ItemGroup>
50-
51-
<ItemGroup>
52-
<None Include="build\Rcl.NET.props" Pack="True" PackagePath="build" Visible="False" />
53-
<None Include="build\Rcl.NET.targets" Pack="True" PackagePath="build" Visible="False" />
54-
</ItemGroup>
55-
56-
<ItemGroup>
57-
<ProjectReference Include="..\ros2cs\ros2cs.csproj">
58-
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
59-
</ProjectReference>
60-
</ItemGroup>
61-
62-
<Import Project="build\ros2cs.targets" />
63-
<Import Project="build\Rcl.NET.props" />
64-
<Import Project="build\Rcl.NET.targets" />
51+
<Import Project="build\Rcl.NET.props" />
52+
<!-- TODO: only generate changed interface packages,
53+
because generating many packages can take considerably long time,
54+
maybe not here but maybe by ros2cs generator code -->
55+
<Import Project="build\Rcl.NET.targets" />
6556

66-
<ItemGroup Condition="'$(_IsPacking)' == 'true'">
67-
<None Include="$(MSBuildProjectDirectory)\..\ros2cs\bin\$(Configuration)\net6.0\publish\*"
68-
Pack="True"
69-
PackagePath="tools\net6.0\ros2cs\"/>
70-
</ItemGroup>
57+
<PropertyGroup>
58+
<Ros2csSourcePublish>$(MSBuildProjectDirectory)\..\ros2cs\bin\$(Configuration)\$(Ros2csBundleTfm)\publish</Ros2csSourcePublish>
59+
</PropertyGroup>
60+
<ItemGroup Condition="'$(_IsPacking)' == 'true'">
61+
<None Include="build\Rcl.NET.props" Pack="True" PackagePath="build" />
62+
<None Include="build\Rcl.NET.targets" Pack="True" PackagePath="build" />
63+
<None Include="$(Ros2csSourcePublish)\*.dll;$(Ros2csSourcePublish)\ros2cs.runtimeconfig.json;$(Ros2csSourcePublish)\ros2cs.deps.json"
64+
Pack="True" PackagePath="tools\$(Ros2csBundleTfm)\ros2cs\" />
65+
</ItemGroup>
66+
67+
<!-- ../Directory.Build.props & .targets are also imported to gather the source ros2cs -->
7168
</Project>

src/Rcl.NET/build/Rcl.NET.props

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22

3+
<PropertyGroup>
4+
<Ros2csOutputDir Condition="$(Ros2csOutputDir) == ''">Ros2csGeneratedInterfaces</Ros2csOutputDir>
5+
<Ros2csBundleTfm>net8.0</Ros2csBundleTfm>
6+
<Ros2csExe Condition="'$(Ros2csExe)' == ''">$(MSBuildThisFileDirectory)\..\tools\$(Ros2csBundleTfm)\ros2cs\ros2cs.dll</Ros2csExe>
7+
</PropertyGroup>
8+
39
<ItemGroup>
410
<Ros2csGenFiles Include="$(IntermediateOutputPath)\$(Ros2csOutputDir)\**\*.g.cs" />
511

6-
<Compile Include="$(IntermediateOutputPath)\$(Ros2csOutputDir)\**\*.g.cs">
12+
<Compile Include="@(Ros2csGenFiles)">
713
<Link>$(Ros2csOutputDir)\%(RecursiveDir)%(Filename)%(Extension)</Link>
814
</Compile>
915
</ItemGroup>

src/Rcl.NET/build/Rcl.NET.targets

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,70 @@
11
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22

3-
<Target Name="GenerateInterfaces_ros2cs" BeforeTargets="CoreCompile">
3+
<PropertyGroup>
4+
<GenerateInterfaces_ros2csDependsOn>
5+
$(GenerateInterfaces_ros2csDependsOn);GetRos2csProps
6+
</GenerateInterfaces_ros2csDependsOn>
7+
</PropertyGroup>
48

5-
<PropertyGroup Condition="'$(Ros2csExe)' == ''">
6-
<Ros2csExe>$(MSBuildThisFileDirectory)\..\tools\net6.0\ros2cs\ros2cs.dll</Ros2csExe>
7-
</PropertyGroup>
9+
<Target Name="GenerateInterfaces_ros2cs" BeforeTargets="BeforeCompile;CoreCompile"
10+
DependsOnTargets="$(GenerateInterfaces_ros2csDependsOn)"
11+
Inputs="$(Ros2csSpecFile)" Outputs="$(IntermediateOutputPath)\$(Ros2csOutputDir)\ros2cs.spec.cache">
812

9-
<PropertyGroup>
10-
<DefaultRos2csSpecFile>$(MSBuildProjectDirectory)\ros2cs.spec</DefaultRos2csSpecFile>
11-
<Ros2csOutputDir Condition="$(Ros2csOutputDir) == ''">Ros2csGeneratedInterfaces</Ros2csOutputDir>
12-
<Ros2csSpecFile Condition="$(Ros2csSpecFile) == '' and Exists('$(DefaultRos2csSpecFile)')">$(DefaultRos2csSpecFile)</Ros2csSpecFile>
13-
<Ros2csCommand>dotnet &quot;$(Ros2csExe)&quot; -o $(IntermediateOutputPath)\$(Ros2csOutputDir) &quot;$(Ros2csSpecFile)&quot;</Ros2csCommand>
14-
</PropertyGroup>
13+
<Message Text="Ros2csSpec: $(Ros2csSpecFile)"/>
1514

16-
<Message Text="Ros2csSpec: $(Ros2csSpecFile)"/>
15+
<Message Text="Ros2csCmd: $(Ros2csCommand)"/>
1716

18-
<Message Text="Ros2csCmd: $(Ros2csCommand)"/>
17+
<Exec Command="$(Ros2csCommand)" WorkingDirectory="$(MSBuildProjectDirectory)"
18+
ConsoleToMSBuild="true" IgnoreExitCode="true" Condition="'$(Ros2csSpecFile)' != ''">
19+
20+
<Output TaskParameter="ConsoleOutput" ItemName="Ros2csOutput"/>
21+
<Output TaskParameter="ExitCode" PropertyName="Ros2csExitCode"/>
22+
</Exec>
23+
24+
<Error Condition="'$(Ros2csSpecFile)' != '' and '$(Ros2csExitCode)' != '0'"
25+
Text="'$(Ros2csCommand)' failed with exit code $(Ros2csExitCode):&#x0A;@(Ros2csOutput->'%(Identity)', '&#x0A;')" />
1926

20-
<Exec Command="$(Ros2csCommand)" WorkingDirectory="$(MSBuildProjectDirectory)"
21-
ConsoleToMSBuild="true" IgnoreExitCode="true" Condition="'$(Ros2csSpecFile)' != ''">
27+
<Copy SourceFiles="$(Ros2csSpecFile)"
28+
DestinationFiles="$(IntermediateOutputPath)\$(Ros2csOutputDir)\ros2cs.spec.cache"
29+
SkipUnchangedFiles="true"
30+
Condition="'$(Ros2csSpecFile)' != ''"/>
31+
32+
<ItemGroup>
33+
<Compile Remove="@(Ros2csGenFiles)" />
34+
<Compile Include="$(IntermediateOutputPath)\$(Ros2csOutputDir)\**\*.g.cs"/>
35+
</ItemGroup>
36+
</Target>
2237

23-
<Output TaskParameter="ConsoleOutput" ItemName="Ros2csOutput"/>
24-
<Output TaskParameter="ExitCode" PropertyName="Ros2csExitCode"/>
25-
</Exec>
2638

27-
<Error Condition="'$(Ros2csSpecFile)' != '' and '$(Ros2csExitCode)' != '0'"
28-
Text="ros2cs failed with exit code $(Ros2csExitCode):&#x0A;@(Ros2csOutput->'%(Identity)', '&#x0A;')" />
39+
<PropertyGroup>
40+
<CleanGenerated_ros2csDependsOn>
41+
$(CleanGenerated_ros2csDependsOn);GetRos2csProps
42+
</CleanGenerated_ros2csDependsOn>
43+
</PropertyGroup>
2944

30-
<ItemGroup>
31-
<Compile Remove="@(Ros2csGenFiles)"/>
32-
<Compile Include="$(IntermediateOutputPath)\$(Ros2csOutputDir)\**\*.g.cs"/>
33-
</ItemGroup>
34-
</Target>
45+
<Target Name="CleanGenerated_ros2cs" BeforeTargets="CoreClean" DependsOnTargets="$(CleanGenerated_ros2csDependsOn)">
46+
<RemoveDir Directories="$(IntermediateOutputPath)\$(Ros2csOutputDir)" />
47+
</Target>
3548

36-
<Target Name="CleanGenerated_ros2cs" BeforeTargets="CoreClean">
37-
<RemoveDir Directories="$(IntermediateOutputPath)\$(Ros2csOutputDir)" />
38-
</Target>
49+
50+
<Target Name="GetRos2csProps" DependsOnTargets="$(GetRos2csPropsDependsOn)">
51+
<PropertyGroup>
52+
<DefaultRos2csSpecFile>$(MSBuildProjectDirectory)\ros2cs.spec</DefaultRos2csSpecFile>
53+
<Ros2csSpecFile Condition="$(Ros2csSpecFile) == '' and Exists('$(DefaultRos2csSpecFile)')">$(DefaultRos2csSpecFile)</Ros2csSpecFile>
54+
55+
<Ros2csCommand>dotnet $(Ros2csExe.Trim()) $(Ros2csArgs.Trim()) -o &quot;$(IntermediateOutputPath)\$(Ros2csOutputDir.Trim())&quot; &quot;$(Ros2csSpecFile.Trim())&quot;</Ros2csCommand>
56+
</PropertyGroup>
57+
</Target>
58+
59+
60+
<Target Name="CheckAmentPrefixPath" AfterTargets="GetRos2csProps">
61+
<ReadLinesFromFile File="$(Ros2csSpecFile)">
62+
<Output TaskParameter="Lines" ItemName="Ros2csSpecFileLines"/>
63+
</ReadLinesFromFile>
64+
65+
<Warning Code="RCL0002" File="$(Ros2csSpecFile)"
66+
Condition="'$(AMENT_PREFIX_PATH)' == '' AND @(Ros2csSpecFileLines->AnyHaveMetadataValue('Identity', 'from-ament-index'))"
67+
Text="'from-ament-index' option is specified in ros2cs.spec file but 'AMENT_PREFIX_PATH' Property or Environment Variable is not set/empty. ROS 2 interface packages may not be found." />
68+
</Target>
3969

4070
</Project>

src/Rcl.NET/build/ros2cs.targets

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Rosidl.Generator.CSharp/Rosidl.Generator.CSharp.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<!--<TargetFramework>net9.0</TargetFramework>-->
56
<ImplicitUsings>enable</ImplicitUsings>
67
<Nullable>enable</Nullable>
78
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -10,7 +11,9 @@
1011
</PropertyGroup>
1112

1213
<ItemGroup>
13-
<PackageReference Include="CppAst.CodeGen" Version="0.11.3" />
14+
<PackageReference Include="CppAst.CodeGen" Version="0.11.3" />
15+
<!--<PackageReference Include="CppAst.CodeGen" Version="0.27.0" />
16+
<PackageReference Include="LibGit2Sharp" Version="0.31.0" />-->
1417
</ItemGroup>
1518

1619
</Project>

src/Rosidl.Runtime/Rosidl.Runtime.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

0 commit comments

Comments
 (0)