Hello,
This is the error I am receiving:
"Messages while compiling C:\Users\Documents\Unreal Projects\myproject\Intermediate\Build\BuildRules\myprojectModuleRules.dll:
C:\Users\Documents\Unreal Projects\myproject\Source\myprojectServer.Target.cs(6,14) : error CS0101: The namespace ‘’ already contains a definition for ‘myprojectServerTarget’ "
Windows 10 Pro
Unreal 4.17.2
Visual Studio Community 2017
These are the files I am working with…
myproject.Target.cs
using UnrealBuildTool;
using System.Collections.Generic;
[SupportedPlatforms(UnrealPlatformClass.Server)]
public class myprojectServerTarget : TargetRules
{
public myprojectServerTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Server;
ExtraModuleNames.Add("myproject");
}
}
myprojectServer.Target.cs
using UnrealBuildTool;
using System.Collections.Generic;
public class myprojectServerTarget : TargetRules
{
public myprojectServerTarget(TargetInfo Target)
{
Type = myprojectServerTarget.Server;
bUsesSteam = true;
}
//
// TargetRules interface.
//
public override bool GetSupportedPlatforms(ref List<UnrealTargetPlatform> OutPlatforms)
{
// It is valid for only server platforms
return UnrealBuildTool.UnrealBuildTool.GetAllServerPlatforms(ref OutPlatforms, false);
}
public override void SetupBinaries
(
TargetInfo Target, ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
ref List<string> OutExtraModuleNames
)
{
OutExtraModuleNames.Add("myproject");
}
}
I am having been trying to figure this out for awhile. Scoured google and the forums and, while others seem to have similar problems, I don't think I've made the exact mistakes (who knows). Any help would be greatly appreciated.
Thanks!
The *.Target.cs file shouldn’t define the server target. That should just be in the *Server.Target.cs file. The *.Target.cs file is for the non-server target, aka the standard game target (for standalone and client games). The Editor.Target.cs file has its own too. The main difference is in the “Type =” statement. You need those to match the file names, TargetType.Server with *Server.Target.cs and so on.
I think what’s happening is you have the server target defined in both cs files. If you can simply restore the *.Target.cs file to what it was before you changed it, then that would be the quickest fix. Or copy the one generated for a template project.
So basically, you want myproject.Target.cs to declare myprojectTarget instead of myprojectServerTarget – and change “Type = TargetType.Server;” to “Type = TargetType.Game;”.
(I had to post this an an answer because the site would not let me respond to the previous answer or post as a regular comment)
Thank you for responding!
I made the changes that you described above. Your explanation made a lot of sense. Now I am getting a different error. Progress!
warning CS0618: ‘UnrealBuildTool.TargetRules.TargetRules()’ is obsolete: ‘Please pass the TargetInfo parameter to the base class constructor (eg. “MyTargetRules(TargetInfo Target) : base(Target)”).’
error CS0122: ‘UnrealBuildTool.UnrealBuildTool’ is inaccessible due to its protection level
error CS0117: ‘UnrealBuildTool.UnrealBuildTool’ does not contain a definition for ‘GetAllServerPlatforms’
UnrealBuildTool Exception:
ERROR: UnrealBuildTool encountered an error while compiling source files**
myprojectTarget.cs
using UnrealBuildTool;
using System.Collections.Generic;
[SupportedPlatforms(UnrealPlatformClass.Server)]
public class myprojectTarget : TargetRules // Change this line as shown previously
{
public myprojectTarget(TargetInfo Target) : base(Target) // Change this line as shown previously
{
Type = TargetType.Game;
ExtraModuleNames.Add("myproject"); // Change this line as shown previously
}
}
myprojectServerTarget.cs
using UnrealBuildTool;
using System.Collections.Generic;
public class myprojectServerTarget : TargetRules
{
public myprojectServerTarget(TargetInfo Target)
{
Type = TargetType.Server;
bUsesSteam = true;
}
//
// TargetRules interface.
//
public override bool GetSupportedPlatforms(ref List<UnrealTargetPlatform> OutPlatforms)
{
// It is valid for only server platforms
return UnrealBuildTool.UnrealBuildTool.GetAllServerPlatforms(ref OutPlatforms, false);
}
public override void SetupBinaries
(
TargetInfo Target, ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
ref List<string> OutExtraModuleNames
)
{
OutExtraModuleNames.Add("myproject");
}
}
Is this maybe because the code in the Server.Target.cs does not work for my version of Unreal?
Thanks again!
I fixed it!
If anyone else is having this problem here is what I did. The target.cs file remained the same but I changed the servertarget.cs file so it basically mirrored the syntax and structure of the target.cs file. The code I was trying to use is obsolete for 4.17.2
Thanks for the help.