-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dotnet tools targeting Windows APIs #12055
Comments
at the same time I don't think we have |
my opinion is this is a low priority. I don't think there are many tools want to access platform specific API. We could ship without this support and see the reaction. |
It would be lovely if this makes it into the .NET 6 release ;). As in the other issue described, I have exactly the bluetooth case described in the original description. |
I would also use this, my use case is showing Toast notifications if the platform allows it. |
We also got use cases. For example we got cli tools which got large lists of options as input. |
How can I ignore the NETSDK1146 error? |
One of the hack code (Beaking in .NET 8): <Target Name="HackBeforePackToolValidation" BeforeTargets="_PackToolValidation">
<PropertyGroup>
<TargetPlatformIdentifier></TargetPlatformIdentifier>
</PropertyGroup>
</Target>
<Target Name="HackAfterPackToolValidation" AfterTargets="_PackToolValidation">
<PropertyGroup>
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
</PropertyGroup>
</Target> Update in #12055 (comment) |
Pardon my ignorance, but where should I put that code? <Project Sdk="Microsoft.NET.Sdk">
...
<Target Name="HackBeforePackToolValidation" BeforeTargets="_PackToolValidation">
....
</Target>
</Project> but didn't work. It throws an error "MSB4232 Items that are outside Target elements must have one of the following operations: Include, Update, or Remove." So I suppose I need to create some other file related to msbuild, but I'm not familiar with that process. |
@LazaroOnline did you place the Target element within an ItemGroup element. I expect that would cause the MSB4232 error. If you did, move it out. If you didn't, please show in more detail what you did. |
@KalleOlaviNiemitalo yes, I also tried placing it into an ItemGroup and had the same error message. <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<PackAsTool>True</PackAsTool>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
</ItemGroup>
<Target Name="HackBeforePackToolValidation" BeforeTargets="_PackToolValidation">
<PropertyGroup>
<TargetPlatformIdentifier></TargetPlatformIdentifier>
</PropertyGroup>
</Target>
<Target Name="HackAfterPackToolValidation" AfterTargets="_PackToolValidation">
<PropertyGroup>
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
</PropertyGroup>
</Target>
</Project> Error: |
The Target elements should not be inside the ItemGroup element. |
@KalleOlaviNiemitalo True, I got it to work without the ItemGroup, however VisualStudio seems to have some stability problems handling these manual changes, it intermittently complains about the csproj. Anyway, even if I could pack it as a nuget dotnet-tool, and publish it to nuget.org, it fails when the user tries to install, since in my case I only have 1 target |
At @lindexi I tired adding this hack. However when I was installing it, I got an error: $ dotnet tool install MyApp--global
Tool 'xxxxxxxxxxxxxxxx.xxxxx' failed to update due to the following:
The settings file in the tool's NuGet package is invalid: Settings file 'DotnetToolSettings.xml' was not found in the package.
Tool 'xxxxxxxxxxxxxxxx.xxxxx' failed to install. Contact the tool author for assistance. I tried to download the nupkg and unzip it locally, but found |
@Anduin2017 Update the hack csproj code for .NET 8.0 or greater <Target Name="HackBeforePackToolValidation" BeforeTargets="_PackToolValidation">
<PropertyGroup>
<TargetPlatformIdentifier></TargetPlatformIdentifier>
<TargetPlatformMoniker></TargetPlatformMoniker>
</PropertyGroup>
</Target>
<Target Name="HackAfterPackToolValidation" AfterTargets="_PackToolValidation" BeforeTargets="PackTool">
<PropertyGroup>
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
</PropertyGroup>
</Target> All the csproj code: <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<PackAsTool>true</PackAsTool>
<ToolCommandName>lindexi</ToolCommandName>
</PropertyGroup>
<Target Name="HackBeforePackToolValidation" BeforeTargets="_PackToolValidation">
<PropertyGroup>
<TargetPlatformIdentifier></TargetPlatformIdentifier>
<TargetPlatformMoniker></TargetPlatformMoniker>
</PropertyGroup>
</Target>
<Target Name="HackAfterPackToolValidation" AfterTargets="_PackToolValidation" BeforeTargets="PackTool">
<PropertyGroup>
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
</PropertyGroup>
</Target>
</Project> And you can find all my code in https://github.com/lindexi/lindexi_gd/blob/fdd3959ce65cf2ebeead9706c04901caafb1f89c/WinemwhajallawLigawakuja/WinemwhajallawLigawakuja.csproj |
Thank you @lindexi ! I tried your hack an it works! Now I can distribute my WPF app via dotnet tool! |
dotnet PackAsTool is busted since dotnet 5.0 if using windowsforms or wpf (though I definitely had it working with dotnet 7). Not sure the right way to do this, I don't like bringing in windowsforms just to get screen resolution and offsets but i've already spent way too long trying to find another way and there doesn't seem to be one. maybe wmi/cim would work, but i couldn't find if it can report the offsets necessary for ffmpeg to record the screen correctly. I think this workaround basically lies to packastool when it does its check. doesn't seem to have any impact on if it works or not at runtime. see dotnet/sdk#16361 and dotnet/sdk#12055
Due to this issue, WPF and Winforms net5.0 dotnet tools are not available
What happens if a dotent tools targeting net5.0-win and want to call Windows specific API? Say access Bluetooth to help debugging a device.
Currently the target framework selection is choosing the most compatible TFM according to the TFM SDK is built on. In this case, SDK will be built on net5.0, and it won't choose net5.0-win.
This need external dependency. We need runtime team to provide us a mechanism to tell if 5.0 windows runtime is install on the machine, which we've been asked a long time.
The text was updated successfully, but these errors were encountered: