Skip to content

Commit 1571dfd

Browse files
committed
Update ObsWebSocket.SourceGenerators.csproj
use curl instead
1 parent a423d71 commit 1571dfd

1 file changed

Lines changed: 31 additions & 106 deletions

File tree

Lines changed: 31 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<LangVersion>latest</LangVersion>
@@ -10,6 +10,7 @@
1010
<Description>Source Generators for ObsWebSocket.Core library.</Description>
1111
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1212
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
13+
<!-- Suppress NU5128: Some target frameworks are not supported by the nuspec -->
1314
<NoWarn>$(NoWarn);NU5128</NoWarn>
1415
</PropertyGroup>
1516
<ItemGroup>
@@ -22,11 +23,9 @@
2223
Include="Microsoft.CodeAnalysis.Analyzers"
2324
Version="3.11.0"
2425
PrivateAssets="all"
25-
>
26-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
27-
</PackageReference>
26+
/>
2827
</ItemGroup>
29-
<!-- Package References necessary for the Source Generator packaging AND inline task variable -->
28+
<!-- Package References necessary for the Source Generator -->
3029
<ItemGroup Label="Package References">
3130
<PackageReference
3231
Include="System.Text.Json"
@@ -82,19 +81,12 @@
8281
GeneratePathProperty="true"
8382
PrivateAssets="all"
8483
/>
85-
<PackageReference
86-
Include="System.Net.Http"
87-
Version="4.3.4"
88-
PrivateAssets="all"
89-
GeneratePathProperty="true"
90-
/>
9184
</ItemGroup>
9285
<PropertyGroup>
9386
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
94-
<ResolveNuGetPackages>true</ResolveNuGetPackages>
9587
</PropertyGroup>
96-
<!-- Target to copy dependencies for Source Generator Packaging -->
97-
<Target Name="GetDependencyTargetPaths" AfterTargets="ResolvePackageAssets">
88+
<!-- Target to copy dependencies for Source Generator -->
89+
<Target Name="GetDependencyTargetPaths">
9890
<ItemGroup>
9991
<TargetPathWithTargetPlatformMoniker
10092
Include="$(PKGSystem_Text_Json)\lib\netstandard2.0\*.dll"
@@ -132,107 +124,40 @@
132124
Include="$(PKGSystem_IO_Pipelines)\lib\netstandard2.0\*.dll"
133125
IncludeRuntimeDependency="false"
134126
/>
135-
<!-- Keep this: It's needed to package the dependency with the generator -->
136-
<TargetPathWithTargetPlatformMoniker
137-
Include="$(PKGSystem_Net_Http)\lib\netstandard2.0\*.dll"
138-
IncludeRuntimeDependency="false"
139-
/>
140127
</ItemGroup>
141128
</Target>
142129
<!-- Files for Analyzer Release Tracking (RS2008) -->
143130
<ItemGroup>
144131
<AdditionalFiles Include="AnalyzerReleases.*.md" />
145132
</ItemGroup>
146-
<!-- Define the inline task -->
147-
<UsingTask
148-
TaskName="DownloadFileTask"
149-
TaskFactory="CodeTaskFactory"
150-
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"
151-
>
152-
<ParameterGroup />
153-
<Task>
154-
<Reference Include="System.Net.Http" />
155-
<Reference Include="netstandard" />
156-
<Using Namespace="System" />
157-
<Using Namespace="System.IO" />
158-
<Using Namespace="System.Net.Http" />
159-
<Using Namespace="System.Threading.Tasks" />
160-
<Code Type="Fragment" Language="cs">
161-
<![CDATA[
162-
string url = "https://raw.githubusercontent.com/obsproject/obs-websocket/master/docs/generated/protocol.json";
163-
string outputPath = Path.Combine("..", "protocol.json");
164-
string fullOutputPath = Path.GetFullPath(outputPath);
165-
166-
string directory = Path.GetDirectoryName(fullOutputPath);
167-
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
168-
{
169-
Log.LogMessage(MessageImportance.Normal, "Creating directory: " + directory);
170-
Directory.CreateDirectory(directory);
171-
}
172-
173-
try
174-
{
175-
Log.LogMessage(MessageImportance.High, "Attempting to download protocol.json from " + url + " to " + fullOutputPath);
176-
177-
using (HttpClient client = new HttpClient())
178-
{
179-
client.DefaultRequestHeaders.UserAgent.ParseAdd("ObsWebSocket.Core-Build/1.0 (MSBuild Task)");
180-
client.Timeout = TimeSpan.FromSeconds(30);
181-
string content = client.GetStringAsync(url).Result;
182-
File.WriteAllText(fullOutputPath, content);
183-
Log.LogMessage(MessageImportance.High, "Successfully downloaded and saved protocol.json to " + fullOutputPath);
184-
}
185-
}
186-
catch (AggregateException ae)
187-
{
188-
HttpRequestException httpEx = ae.InnerException as HttpRequestException;
189-
if (httpEx != null)
190-
{
191-
// REMOVED StatusCode from format string
192-
Log.LogError(string.Format("HTTP Error downloading protocol.json: {0}", httpEx.Message));
193-
Log.LogErrorFromException(httpEx, true, true, null);
194-
}
195-
else
196-
{
197-
Log.LogError("Aggregate error during download.");
198-
Log.LogErrorFromException(ae, true, true, null);
199-
}
200-
Success = false;
201-
return false;
202-
}
203-
catch (HttpRequestException httpEx)
204-
{
205-
// REMOVED StatusCode from format string
206-
Log.LogError(string.Format("HTTP Error downloading protocol.json: {0}", httpEx.Message));
207-
Log.LogErrorFromException(httpEx, true, true, null);
208-
Success = false;
209-
return false;
210-
}
211-
catch (Exception ex)
212-
{
213-
Log.LogError("Failed to download protocol.json.");
214-
Log.LogErrorFromException(ex, true, true, null);
215-
Success = false;
216-
return false;
217-
}
218-
// No 'return true;' here
219-
]]>
220-
</Code>
221-
</Task>
222-
</UsingTask>
223-
<!-- Target to run the download task -->
133+
<PropertyGroup>
134+
<_ProtocolJsonUrl>https://raw.githubusercontent.com/obsproject/obs-websocket/master/docs/generated/protocol.json</_ProtocolJsonUrl>
135+
<_ProtocolJsonOutputPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\protocol.json'))</_ProtocolJsonOutputPath>
136+
</PropertyGroup>
224137
<Target
225138
Name="DownloadProtocolFile"
226139
BeforeTargets="CoreCompile"
227-
Outputs="..\protocol.json"
228-
Condition="!Exists('..\protocol.json')"
140+
Outputs="$(_ProtocolJsonOutputPath)"
141+
Condition="!Exists('$(_ProtocolJsonOutputPath)')"
229142
>
230-
<Message Text="protocol.json not found or condition met. Downloading..." Importance="high" />
231-
<DownloadFileTask />
143+
<Message
144+
Text="protocol.json not found at '$(_ProtocolJsonOutputPath)'. Downloading from $(_ProtocolJsonUrl)..."
145+
Importance="high"
146+
/>
147+
<Exec
148+
Command="curl '$(_ProtocolJsonUrl)' -o '$(_ProtocolJsonOutputPath)'"
149+
ConsoleToMSBuild="true"
150+
ContinueOnError="false"
151+
/>
152+
<Message Text="protocol.json download attempt finished." Importance="high" />
153+
<!-- Verify download success (optional but good practice) -->
154+
<Error
155+
Text="Failed to download protocol.json. Check curl command output and network connection."
156+
Condition="!Exists('$(_ProtocolJsonOutputPath)') AND '$(OS)' != 'Windows_NT'"
157+
/>
158+
<Warning
159+
Text="Could not verify protocol.json download on Windows using curl. Ensure curl is in PATH."
160+
Condition="!Exists('$(_ProtocolJsonOutputPath)') AND '$(OS)' == 'Windows_NT'"
161+
/>
232162
</Target>
233-
<!-- Ensure the download happens before the generator dependencies are resolved -->
234-
<!-- This might be slightly redundant with BeforeTargets but can help enforce order -->
235-
<PropertyGroup>
236-
<CoreCompileDependsOn>DownloadProtocolFile;$(CoreCompileDependsOn)</CoreCompileDependsOn>
237-
</PropertyGroup>
238163
</Project>

0 commit comments

Comments
 (0)