|
1 | | -<Project Sdk="Microsoft.NET.Sdk"> |
| 1 | +<Project Sdk="Microsoft.NET.Sdk"> |
2 | 2 | <PropertyGroup> |
3 | 3 | <TargetFramework>netstandard2.0</TargetFramework> |
4 | 4 | <LangVersion>latest</LangVersion> |
|
10 | 10 | <Description>Source Generators for ObsWebSocket.Core library.</Description> |
11 | 11 | <EnableNETAnalyzers>true</EnableNETAnalyzers> |
12 | 12 | <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> |
| 13 | + <!-- Suppress NU5128: Some target frameworks are not supported by the nuspec --> |
13 | 14 | <NoWarn>$(NoWarn);NU5128</NoWarn> |
14 | 15 | </PropertyGroup> |
15 | 16 | <ItemGroup> |
|
22 | 23 | Include="Microsoft.CodeAnalysis.Analyzers" |
23 | 24 | Version="3.11.0" |
24 | 25 | PrivateAssets="all" |
25 | | - > |
26 | | - <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
27 | | - </PackageReference> |
| 26 | + /> |
28 | 27 | </ItemGroup> |
29 | | - <!-- Package References necessary for the Source Generator packaging AND inline task variable --> |
| 28 | + <!-- Package References necessary for the Source Generator --> |
30 | 29 | <ItemGroup Label="Package References"> |
31 | 30 | <PackageReference |
32 | 31 | Include="System.Text.Json" |
|
82 | 81 | GeneratePathProperty="true" |
83 | 82 | PrivateAssets="all" |
84 | 83 | /> |
85 | | - <PackageReference |
86 | | - Include="System.Net.Http" |
87 | | - Version="4.3.4" |
88 | | - PrivateAssets="all" |
89 | | - GeneratePathProperty="true" |
90 | | - /> |
91 | 84 | </ItemGroup> |
92 | 85 | <PropertyGroup> |
93 | 86 | <GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn> |
94 | | - <ResolveNuGetPackages>true</ResolveNuGetPackages> |
95 | 87 | </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"> |
98 | 90 | <ItemGroup> |
99 | 91 | <TargetPathWithTargetPlatformMoniker |
100 | 92 | Include="$(PKGSystem_Text_Json)\lib\netstandard2.0\*.dll" |
|
132 | 124 | Include="$(PKGSystem_IO_Pipelines)\lib\netstandard2.0\*.dll" |
133 | 125 | IncludeRuntimeDependency="false" |
134 | 126 | /> |
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 | | - /> |
140 | 127 | </ItemGroup> |
141 | 128 | </Target> |
142 | 129 | <!-- Files for Analyzer Release Tracking (RS2008) --> |
143 | 130 | <ItemGroup> |
144 | 131 | <AdditionalFiles Include="AnalyzerReleases.*.md" /> |
145 | 132 | </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> |
224 | 137 | <Target |
225 | 138 | Name="DownloadProtocolFile" |
226 | 139 | BeforeTargets="CoreCompile" |
227 | | - Outputs="..\protocol.json" |
228 | | - Condition="!Exists('..\protocol.json')" |
| 140 | + Outputs="$(_ProtocolJsonOutputPath)" |
| 141 | + Condition="!Exists('$(_ProtocolJsonOutputPath)')" |
229 | 142 | > |
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 | + /> |
232 | 162 | </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> |
238 | 163 | </Project> |
0 commit comments