- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我们有一个 VS2012 .NET 4 产品,它有 2 个不同的 SKU A 和 B,我们目前仅为 x86 构建。我们还有通常的配置 Debug
和 Release
这意味着我们目前有 4 种配置。
查看其中一个 .csproj 文件,它看起来像这样
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugA|x86' ">
<OutputPath>..\bin\DebugA\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseA|x86' ">
<OutputPath>..\bin\ReleaseA\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugB|x86' ">
<OutputPath>..\bin\DebugB\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseB|x86' ">
<OutputPath>..\bin\ReleaseB\</OutputPath>
</PropertyGroup>
显然,添加 x64 会使这个数量从 4 倍增加到 8 种不同的组合,而且 VS 似乎也会在需要时添加 AnyCPU 平台配置。确保 30 多个项目中的所有 8 个都正确配置需要在 VS 中进行大量点击,而且很容易出错。
我已经阅读了其他一些解决了多目标定位问题的 SO 问题,以及在引用路径中使用 ${Platform} 为不同平台包含不同引用的建议之一。我想我可以为我的项目配置做一些类似的事情,所以我在尝试做多平台时尝试了这个:
<PropertyGroup Condition=" '$(Configuration)' == 'DebugA' Or '$(Configuration)' == 'DebugB' ">
<OutputPath>..\bin\${Platform}\${Configuration}\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseA' Or '$(Configuration)' == 'ReleaseB' ">
<OutputPath>..\bin\${Platform}\${Configuration}\</OutputPath>
</PropertyGroup>
从理论上讲,这应该可以给我所有 8 种不同组合所需的东西,只需要两个积木。但是现在在 VS 中,我看不到 neitehr x86 或 x64 作为项目的可用构建平台。看起来 VS 实际存储构建平台的唯一方法是将它们编码为属性组上的异常条件?说它不是这样......
有没有办法制作一个“漂亮”的多平台 .csproj,它可以很好地与 VS 配合使用?
我可以创建 .csprojs 然后决定不在 VS 中编辑它们,相信 msbuild 将使用正确的平台,即使 VS 无法在各个项目的属性窗口中显示任何平台吗?
编辑:
问题似乎有点困惑:要清楚,我想知道如何设置,维护和概述项目的配置,以及我的解决方案的构建配置,当有很多项目和八种组合时配置|平台。我知道如何手动执行此操作,但并非没有失去理智或在 200 多个属性页面中的任何一个上犯错误。
最佳答案
如果您不介意手动更改项目文件一次,那么您可以将所有共享配置放在一个配置文件中,并从每个项目中引用它。为此,您需要先创建配置文件。此文件只是一个普通的 MsBuild 文件,其中包含您希望在所有项目之间共享的所有信息(如构建配置)。该文件大致如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- VS information -->
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<!-- Default configuration -->
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<!-- Project directories -->
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputPath>$(SolutionDir)\..\build\bin\$(Platform)\$(Configuration)\</OutputPath>
<IntermediateOutputPath>$(SolutionDir)\..\build\temp\bin\obj\$(AssemblyName)\$(Platform)\$(Configuration)\</IntermediateOutputPath>
<!-- Build configuration -->
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE;CODE_ANALYSIS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE;CODE_ANALYSIS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE;CODE_ANALYSIS</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
PropertyGroup
定义整体常量,即所有项目用于所有构建配置的常量。正如您所看到的 OutputPath
您可以使用像 $(Platform)
这样的构建变量和 $(Configuration)
确定二进制文件等的位置。PropertyGroup
还有一些通常由 visual studio 定义的设置,例如ProductVersion
.从技术上讲,您不必移动它们,但如果您关心的话,移动它们确实可以减少项目文件中的困惑情况。一旦你定义了配置文件,假设它叫做BaseConfigurations.targets
, 然后你必须编辑你的项目文件。不幸的是,您必须检查所有项目文件,但您只需执行一次。链接配置文件后,您可以通过更改配置文件更改所有共享配置。
一个普通的项目文件大致如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{33017F71-5A1C-4113-9041-4DD3F58921D0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
为了链接配置文件,您需要:
PropertyGroup
中删除那些已经在你的配置文件中定义的添加行 <SolutionDir Condition="'$(SolutionDir)' == '' or '$(SolutionDir)' == '*undefined*'">$(MSBuildProjectDirectory)\..</SolutionDir>
.如果您仅从 Visual Studio 构建(因为 Visual Studio 自动定义 SolutionDir
变量),则没有必要,但如果您还想通过 MsBuild 构建项目,则这是必需的。此行还假定每个项目都在它自己的子目录中,并且解决方案文件是每个项目文件的上一级目录,即您的结构类似于:
source
MyProject
MyProject.csproj
MySolution.sln
就在第一个 PropertyGroup
下面添加以下行 <Import Project="$(SolutionDir)\BaseConfiguration.targets" />
.这向 MsBuild(以及 Visual Studio)表明您要导入配置文件。
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
.这是在您的配置文件中定义的,因此不再需要。完成所有这些之后,您的项目文件应该如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<SolutionDir Condition="'$(SolutionDir)' == '' or '$(SolutionDir)' == '*undefined*'">$(MSBuildProjectDirectory)\..</SolutionDir>
<ProjectGuid>{33017F71-5A1C-4113-9041-4DD3F58921D0}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
</PropertyGroup>
<Import Project="$(SolutionDir)\BaseConfiguration.targets" />
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
注意事项:
关于c# - 如何同时为 x86 和 x64 配置 VS2012 解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15921006/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!