-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Support Reference Assemblies in SGEN. #24491
Conversation
<TargetSerializationAssembly>%(SerializationAssembly.Identity)</TargetSerializationAssembly> | ||
<TargetSerializationType>@(SerializationAssembly->Metadata('SerializationType'))</TargetSerializationType> | ||
</TargetSerializationAssemblyAndType> | ||
</ItemGroup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ItemGroup
above can be simplified as,
<ItemGroup Condition="@(SerializationAssembly)!=''" Label="Parse SerializationAssembly">
<SearchSerializationAssembly Include="@(Reference)">
<AssemblyName>%(SerializationAssembly.Identity)</AssemblyName>
<SerializationTypes>%(SerializationAssembly.SerializationType)</SerializationTypes>
</SearchSerializationAssembly>
<TargetSerializationAssembly Include="@(SearchSerializationAssembly)" Condition="$([System.String]::new('%(SearchSerializationAssembly.Identity)').EndsWith('%(SearchSerializationAssembly.AssemblyName).dll'))" />
</ItemGroup>
Accordingly, the <Exec>
at line 53 can be simplified as,
<Exec Command="dotnet Microsoft.XmlSerializer.Generator /force /quiet /assembly:%(TargetSerializationAssembly.Identity) /type:%(TargetSerializationAssembly.SerializationTypes) /out:$(IntermediateOutputPath)" ContinueOnError="true" />
<ReferenceSerializerName Include="%(SerializationAssembly.Identity).XmlSerializers" /> | ||
<ReferenceSerializerDllImmediatePath Include="$(IntermediateOutputPath)%(ReferenceSerializerName.Identity).dll" /> | ||
<ReferenceSerializerPdbImmediatePath Include="$(IntermediateOutputPath)%(ReferenceSerializerName.Identity).pdb" /> | ||
<ReferenceSerializerCsImmediatePath Include="$(IntermediateOutputPath)%(ReferenceSerializerName.Identity).cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can keep only one ReferenceSerializerImmediatePath
. It's not easy to distinguish the above 3 items. Besides, it seems in some case we cannot use them.
@@ -79,7 +79,18 @@ private int Run(string[] args) | |||
} | |||
else if (ArgumentMatch(arg, "type")) | |||
{ | |||
types.Add(value); | |||
if (value.Contains(";")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to special case value.Contains(";") == true
. If value is not empty, we can just do value.Split(';')
.
@@ -368,7 +379,16 @@ private void ImportType(Type type, ArrayList mappings, ArrayList importedTypes, | |||
private static Assembly LoadAssembly(string assemblyName, bool throwOnFail) | |||
{ | |||
Assembly assembly = null; | |||
string path = Path.GetFullPath(assemblyName); | |||
string path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be written as,
string path = Path.IsPathRooted(assemblyName) ? assemblyName : Path.GetFullPath(assemblyName);
@@ -173,6 +173,11 @@ internal static Assembly LoadGeneratedAssembly(Type type, string defaultNamespac | |||
name.CodeBase = null; | |||
name.CultureInfo = CultureInfo.InvariantCulture; | |||
string serializerPath = Path.Combine(Path.GetDirectoryName(type.Assembly.Location), serializerName + ".dll"); | |||
if(!File.Exists(serializerPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space after if
@dotnet-bot test OSX x64 Debug Build |
<Target Name="CopySerializer" AfterTargets="PrepareForPublish"> | ||
<Copy Condition="Exists('$(OutputPath)\$(AssemblyName).XmlSerializers.dll')=='true'" SourceFiles="$(OutputPath)\$(AssemblyName).XmlSerializers.dll" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="false" /> | ||
</Target> | ||
|
||
<Target Name="GenerateSerializationAssemblyForReferenceAssembly" AfterTargets="GenerateSerializationAssembly" Condition="@(SerializationAssembly)!=''"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please correct the indent for the changes?
<Csc Condition="Exists('$(IntermediateOutputPath)%(ReferenceSerializerName.Identity).cs') == 'true'" ContinueOnError="true" OutputAssembly="$(IntermediateOutputPath)%(ReferenceSerializerName.Identity).dll" References="@(ReferencePath);@(IntermediateAssembly)" EmitDebugInformation="$(DebugSymbols)" Sources="$(IntermediateOutputPath)%(ReferenceSerializerName.Identity).cs" TargetType="Library" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)" /> | ||
<Warning Condition="Exists('$(IntermediateOutputPath)%(ReferenceSerializerName.Identity).dll') != 'true' And Exists('$(IntermediateOutputPath)%(ReferenceSerializerName.Identity).cs') == 'true'" Text="SGEN : warning SGEN1: Fail to compile %(ReferenceSerializerName.Identity).cs. Please follow the instructions in https://go.microsoft.com/fwlink/?linkid=858594 and try again." /> | ||
<Copy Condition="Exists('%(ReferenceSerializeImmediatePath.Identity).dll') == 'true'" SourceFiles="%(ReferenceSerializeImmediatePath.Identity).dll" DestinationFolder="$(OutputPath)" /> | ||
</Target> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add a target, like the target CopySerializer
above, for publishing the generated assemblies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add CopySerializerForReferenceAssemblies
@@ -79,7 +79,14 @@ private int Run(string[] args) | |||
} | |||
else if (ArgumentMatch(arg, "type")) | |||
{ | |||
types.Add(value); | |||
if(value != string.Empty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space after if
types.Add(value); | ||
if(value != string.Empty) | ||
{ | ||
var typelist = value.Split(';'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'var' -> string[]
types.Add(value); | ||
if(value != string.Empty) | ||
{ | ||
string[] typelist = value.Split(';'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
';' [](start = 60, length = 3)
Is making sgen handle the semi-colon the way we wish to handle this as this is different from sg? If it is, that's fine but if we want to use a comma in the tool, then we can do the change in msbuild.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is different from sg desktop version, which is using /type: type1 /type:type2
Where you say ImmediatePath do you mean IntermediatePath? Refers to: src/Microsoft.XmlSerializer.Generator/pkg/build/Microsoft.XmlSerializer.Generator.targets:4 in c37e15f. [](commit_id = c37e15f, deletion_comment = False) |
at Refers to: src/Microsoft.XmlSerializer.Generator/pkg/build/Microsoft.XmlSerializer.Generator.targets:7 in c37e15f. [](commit_id = c37e15f, deletion_comment = False) |
<Target Name="CleanSerializationAssembly" AfterTargets="CoreClean"> | ||
<Message Text="Cleaning serialization files..." Importance="normal"/> | ||
<Delete Condition="Exists('$(OutputPath)\$(SerializerName).dll') == 'true'" Files="$(OutputPath)\$(SerializerName).dll" /> | ||
</Target> | ||
|
||
<Target Name="CopySerializer" AfterTargets="PrepareForPublish"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CopySerializer [](start = 16, length = 14)
To keep consistent naming with the other targets, this should be CopySerializationAssembly
Any properties that an end user would not manipulate/specify in their csproj should be prefixed with _ Refers to: src/Microsoft.XmlSerializer.Generator/pkg/build/Microsoft.XmlSerializer.Generator.targets:4 in c37e15f. [](commit_id = c37e15f, deletion_comment = False) |
<SerializationTypes>%(SerializationAssembly.SerializationType)</SerializationTypes> | ||
</SearchSerializationAssembly> | ||
<TargetSerializationAssembly Include="@(SearchSerializationAssembly)" Condition="$([System.String]::new('%(SearchSerializationAssembly.Identity)').EndsWith('%(SearchSerializationAssembly.AssemblyName).dll'))" /> | ||
<ReferenceSerializerName Include="%(SerializationAssembly.Identity).XmlSerializers" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReferenceSerializerName [](start = 7, length = 23)
Inconsistent naming. Should this be ReferenceSerializationAssemblyName?
If deleting the dll fails, will the build continue of fail? We should fail otherwise later checks with conditions might not get an error and act like it was successful. This can happen if the application is still running. Refers to: src/Microsoft.XmlSerializer.Generator/pkg/build/Microsoft.XmlSerializer.Generator.targets:11 in c37e15f. [](commit_id = c37e15f, deletion_comment = False) |
c37e15f
to
2d913b5
Compare
@dotnet-bot test OSX x64 Debug Build |
@dotnet-bot test Windows x64 Debug Build |
@dotnet-bot test Windows x86 Release Build |
<SGenWarningText>SGEN : warning SGEN1: Fail to generate the serializer for $(AssemblyName).dll. Please follow the instructions in https://go.microsoft.com/fwlink/?linkid=858594 and try again.</SGenWarningText> | ||
<_SerializerName>$(AssemblyName).XmlSerializers</_SerializerName> | ||
<_SerializerDllIntermediatePath>$(IntermediateOutputPath)$(_SerializerName).dll</_SerializerDllIntermediatePath> | ||
<_SerializerPdbIntermediatePath>$(IntermediateOutputPath)$(_SerializerName).pdb</_SerializerPdbIntermediatePath> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, Path = folder, Filename = file
<SerializerCsImmediatePath>$(IntermediateOutputPath)$(SerializerName).cs</SerializerCsImmediatePath> | ||
<SGenWarningText>SGEN : warning SGEN1: Fail to generate the serializer for $(AssemblyName).dll. Please follow the instructions in https://go.microsoft.com/fwlink/?linkid=858594 and try again.</SGenWarningText> | ||
<_SerializerName>$(AssemblyName).XmlSerializers</_SerializerName> | ||
<_SerializerDllIntermediatePath>$(IntermediateOutputPath)$(_SerializerName).dll</_SerializerDllIntermediatePath> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SerializationAssemblyName?
@dotnet-bot test OSX x64 Debug Build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dotnet-bot test OSX x64 Debug Build |
* Support Reference Assemblies in SGEN. * Several fixes based on Shin's feedback. * minor change. * Publish serializer for reference assemblies. * Add publish * correct the assembly name to be copied * small format and naming change. * Add a space. * Rename some variables. * Rename some variables.
* Support Reference Assemblies in SGEN. * Several fixes based on Shin's feedback. * minor change. * Publish serializer for reference assemblies. * Add publish * correct the assembly name to be copied * small format and naming change. * Add a space. * Rename some variables. * Rename some variables.
* Support Reference Assemblies in SGEN. * Several fixes based on Shin's feedback. * minor change. * Publish serializer for reference assemblies. * Add publish * correct the assembly name to be copied * small format and naming change. * Add a space. * Rename some variables. * Rename some variables. Commit migrated from dotnet/corefx@f7ed59d
Customer can define the reference assemblies as well as the related types that need pregenerated serializer as the followings.
Fix #22937
@shmao @mconnew @zhenlan