2

I have C# application with Visual Studio 2010. I want per-configuration assembly names. That is, I need different assembly names for debug and release configuration. So i edited my csproj as below.

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
 <PropertyGroup>
    <...>
    <...>
  </PropertyGroup>
  <Choose>
    <When Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
      <PropertyGroup>
        <AssemblyName>MyApplication</AssemblyName>
      </PropertyGroup>
    </When>
    <When Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
      <PropertyGroup>
        <AssemblyName>MyApplicationd</AssemblyName>
      </PropertyGroup>
    </When>
  </Choose>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    <...>
    <OutputPath>..\..\..\..\utils\debug\Project\x64\</OutputPath>
    <...>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    <...>
    <OutputPath>..\..\..\..\utils\release\Project\x64\</OutputPath>
    <...>
  </PropertyGroup>
</Project>

The build was success and I got MyApplication.exe for release configuration and MyApplicationd.exe for Debug configuration. But when I, F5/F10 to run the project in Debug mode, I am getting below error.

Visual Studio cannot start debugging because the debug target is missing. Please build the project and retry, or set the OutputPath and AssemblyName properties appropriately to point at the correct location for the target assembly.

How can I resolve this? How can I specifying different assembly names based on configuration in project file ?

Kaizen
  • 219
  • 2
  • 17
  • Check your Build configuration manager under Build menu, do you enable the build option for your projects? Or you use the AssemblyConfiguration attribute: http://stackoverflow.com/questions/1093338/vs2008-outputting-a-different-file-name-for-debug-release-configurations – Jack Zhai Oct 19 '16 at 10:34
  • @Jack Zhai: Build was success. The problem is, I am not able to debug in Debug mode. It tells that "MyApplication.exe" was not found (i.e. the debugger attempts to launch the assembly with the wrong AssemblyName). But able to debug in Release mode. – Kaizen Oct 19 '16 at 12:34

1 Answers1

1

It would be not the output path issue, I think it would be related to the assembly name.

My understanding is that you got the detailed error list:

"Visual Studio cannot start debugging because the debug target"xxx\xxx\MyApplication" is missing"(Note: It is not the MyApplicationd). Am I right?

Right click your project->Property->Application, if you check your Assembly name, my understanding is that it would be the name of the release name "MyApplication". If you really want to debug it in debug mode, the name of this property need to be "MyApplicationd", of course, the release mode would not work if you use the debug assembly name.

My understanding is that we could edit UI assembly name in project property and then generate the xml code in your .xxproj file, but if you edit the proj file directly, it wouldn't change it under the UI automatically.

I also using this way here:

Change assembly name based on configuration (Visual Studio 2005/2008)

But it has the same error messages as yours.

The way you use seems to be related to the MSBuild command line:

Change name of exe depending on conditional compilation symbol

enter image description here

Community
  • 1
  • 1
Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
  • Yes. The assembly name should be "MyApplication" in release mode and "MyApplicationd" in debug mode. When I change Release\Debug mode, Is there any mechanism to change it under the UI automatically? – Kaizen Oct 21 '16 at 05:06
  • @Kaizen, edit it in project property manually is the workaround I can think of, I don't achieve it using the post build event even if other members also think about using this way: http://stackoverflow.com/questions/208084/how-to-use-a-different-assembly-name-for-different-configurations, but I think edit it manually is much convenient. – Jack Zhai Oct 21 '16 at 05:52