【问题标题】:visual studio customize the default build propertiesVisual Studio 自定义默认构建属性
【发布时间】:2022-08-23 14:05:07
【问题描述】:

我的应用程序.csproj

<Project Sdk=\"Microsoft.NET.Sdk.WindowsDesktop\">    

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <UseWindowsForms>true</UseWindowsForms>
    
    <TargetFrameworks>net48;net5.0-windows</TargetFrameworks>
    <Configurations>Release</Configurations>
    <Platforms>AnyCPU;x64;x86</Platforms>
    <RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
    
    <SelfContained>false</SelfContained>

  </PropertyGroup>

  <PropertyGroup Condition=\"\'$(Configuration)|$(Platform)\'==\'Release|x64\' And \'$(TargetFramework)\'==\'net5.0-windows\' And \'$(RuntimeIdentifier)\'==\'win-x64\'\">
    <OutputPath>..\\..\\app\\</OutputPath>
    <AssemblyName>my-app</AssemblyName>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
  </PropertyGroup>
  
  <PropertyGroup Condition=\"\'$(Configuration)|$(Platform)\'==\'Release|x86\' And \'$(TargetFramework)\'==\'net5.0-windows\' And \'$(RuntimeIdentifier)\'==\'win-x86\'\">
    <OutputPath>..\\..\\x86\\app\\</OutputPath>
    <AssemblyName>my-app</AssemblyName>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
  </PropertyGroup>      
</Project>

这些命令在 \"....\\app\" 和 \"....\\x86\\app\" 文件夹中构建 x64 和 x86 程序集

msbuild.exe \"MyApp.csproj\" /t:restore;rebuild /p:RuntimeIdentifier=win-x64
msbuild.exe \"MyApp.csproj\" /t:restore;rebuild /p:RuntimeIdentifier=win-x86

但在 Visual Studio 中单击 Build (Ctrl+F5) 或 Debug (F5) 输出到 \"bin\\Release\\net5.0-windows\" 目录。

如何强制 Build (Ctrl+F5) 和 Debug (F5) 执行与此命令相同的操作:

msbuild.exe \"MyApp.csproj\" /t:restore;rebuild /p:RuntimeIdentifier=win-x64
  • 在 Visual Studio 中构建时,您的活动“配置/平台”是否设置为“发布/任何 CPU”?将平台更改为 \'x64\' 是否会将 OutputPath 更改为 \"..\\..\\app\\\"?
  • 在配置管理器中将 AnyCpu 设置为 x64 或 x86,那么 Build 和 Debug 可以和命令一样做吗?
  • 你好,有关于这个问题的更新吗?
  • 将配置管理器更改为 Release|x64 输出到 bin\\x64\\Release\\net5.0-windows

标签: c# visual-studio msbuild csproj


【解决方案1】:

这是我的代码:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFrameworks>net5.0-windows;net472</TargetFrameworks>
    <Nullable>disable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
    <Configurations>Release</Configurations>
    <Platforms>AnyCPU;x64;x86</Platforms>
    <SelfContained>false</SelfContained>
  </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
        <OutputPath>..\..\app\</OutputPath>
        <AssemblyName>my-app</AssemblyName>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
        <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
        <OutputPath>..\..\x86\app\</OutputPath>
        <AssemblyName>my-app</AssemblyName>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
        <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    </PropertyGroup>
</Project>

您可以参考以下步骤来解决此问题:

1.选择目标框架.net5.0-windows

2.选择平台x86

3.使用按钮或F5调试您的项目

4.更改平台x64并调试它。

5.最后我们可以得到这些文件夹。

【讨论】:

    猜你喜欢
    • 2018-08-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    相关资源
    最近更新 更多