如何在JetBrains Rider中创建可用的app.manifest文件以获取管理员权限?
Hey there, let's get your app up and running properly. The crash you're seeing is almost certainly due to an invalid app.manifest file—missing required XML structure or syntax errors are common culprits here. Let's break down how to fix this:
1. Generate a Valid App Manifest Template in Rider
The easiest way to get a correct manifest is to let Rider generate it for you:
- Right-click your project in the Solution Explorer
- Hover over Add → select New Item
- In the search bar, type "Application Manifest File" and select it
- Click Add—this will create a fully compliant manifest with all necessary XML structure
2. The Standard Manifest Template (With Admin Rights Config)
The generated template will look like this. You only need to modify the requestedExecutionLevel section (which you already have right):
<?xml version="1.0" encoding="utf-8"?> <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <!-- Change this line to require admin rights --> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> </requestedPrivileges> </security> </trustInfo> <!-- Optional: Add other manifest sections if needed --> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <!-- Windows 10 compatibility --> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> </application> </compatibility> </assembly>
3. Verify Your Project Configuration
Your .csproj setup looks correct, but double-check:
- Ensure
app.manifestis located in the root of your project (same directory as your.csprojfile) - If you placed it in a subfolder, update the path in
<ApplicationManifest>(e.g.,<ApplicationManifest>Properties/app.manifest</ApplicationManifest>)
4. Troubleshooting the Crash
If replacing with the standard template doesn't fix the crash:
- Clean and rebuild your project: Go to Build → Clean Solution, then Build → Rebuild Solution to clear any cached build artifacts
- Check for XML errors: Open
app.manifestin Rider—any syntax issues (unclosed tags, wrong namespaces) will be highlighted in red - Rule out other admin-related issues: When running as admin, your app has restricted access to certain user-specific folders (like
DocumentsorAppData). If your code tries to write to these without handling permissions, that could cause a crash unrelated to the manifest itself.
Give these steps a try, and your app should stop crashing while still getting the admin rights it needs to run netsh commands.
内容的提问来源于stack exchange,提问作者Quicksoapy

