Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use file name as project name instead of assembly name #289

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ For example, you want to leave out a `ProjectReference` because you know it won'
</ItemGroup>
```

## Why are the project names in my solution file the file name of the project without the extension?
This is the default behavior of Visual Studio to use the file name without the extension for the name of a project in the solution. You can change this behavior by setting the `SlnGenProjectName` property:

For example, this changes the name of the project in the solution to be the same as the assembly name:
```xml
<PropertyGroup>
<SlnGenProjectName Condition="'$(SlnGenProjectName)' == ''">$(AssemblyName)</SlnGenProjectName>
</PropertyGroup>
```

## How do I troubleshoot SlnGen?
You can generate a diagnostic log by specifying the `--binarylogger` command-line parameter:

Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ Use the following properties and items to customize the generated Solution file.
| `IncludeInSolutionFile` | Indicates whether or not a project should be included in a generated Solution file. | `true` or `false` | `true` |
| `SlnGenFolders` | Indicates whether or not a hierarchy of folders should be created. If `false`, the projects are in a flat list. | `true` or `false` | `true` |
| `SlnGenIsDeployable` | Indicates whether or not a project is considered deployable by Visual Studio. | `true` or `false` | `false` <br />Service Fabric projects are automatically set to `true` |
| `SlnGenSolutionFolder` | Specifies a solution folder to place the project in. `SlnGenFolders` must be `false`. | | |
| `SlnGenSolutionFolder` | Specifies a solution folder to place the project in. `SlnGenFolders` must be `false`. | | |
| `SlnGenProjectName` | Specifies the display name of the project in the solution. | | Project file name without file extension |

| Item | Description |
|------|-------------|
Expand Down
101 changes: 101 additions & 0 deletions src/Microsoft.VisualStudio.SlnGen.Tool/build.summary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,114 @@ net5.0:
- NETCOREAPP3_1_OR_GREATER
- TRACE
outputs:
- bin/Debug/slngen/net472/McMaster.Extensions.CommandLineUtils.dll
- bin/Debug/slngen/net472/Microsoft.Diagnostics.Tracing.EventSource.dll
- bin/Debug/slngen/net472/Microsoft.Extensions.FileSystemGlobbing.dll
- bin/Debug/slngen/net472/Microsoft.VisualStudio.RemoteControl.dll
- bin/Debug/slngen/net472/Microsoft.VisualStudio.Setup.Configuration.Interop.dll
- bin/Debug/slngen/net472/Microsoft.VisualStudio.Telemetry.dll
- bin/Debug/slngen/net472/Microsoft.VisualStudio.Utilities.Internal.dll
- bin/Debug/slngen/net472/Newtonsoft.Json.dll
- bin/Debug/slngen/net472/slngen.exe
- bin/Debug/slngen/net472/slngen.exe.config
- bin/Debug/slngen/net472/System.ValueTuple.dll
- bin/Debug/slngen/net5.0/McMaster.Extensions.CommandLineUtils.dll
- bin/Debug/slngen/net5.0/Microsoft.Extensions.FileSystemGlobbing.dll
- bin/Debug/slngen/net5.0/Microsoft.VisualStudio.RemoteControl.dll
- bin/Debug/slngen/net5.0/Microsoft.VisualStudio.Setup.Configuration.Interop.dll
- bin/Debug/slngen/net5.0/Microsoft.VisualStudio.Telemetry.dll
- bin/Debug/slngen/net5.0/Microsoft.VisualStudio.Utilities.Internal.dll
- bin/Debug/slngen/net5.0/Microsoft.Win32.SystemEvents.dll
- bin/Debug/slngen/net5.0/Newtonsoft.Json.dll
- bin/Debug/slngen/net5.0/runtimes/unix/lib/netcoreapp3.0/System.Drawing.Common.dll
- bin/Debug/slngen/net5.0/runtimes/win/lib/netcoreapp2.0/System.Diagnostics.PerformanceCounter.dll
- bin/Debug/slngen/net5.0/runtimes/win/lib/netcoreapp2.0/System.Management.dll
- bin/Debug/slngen/net5.0/runtimes/win/lib/netcoreapp3.0/Microsoft.Win32.SystemEvents.dll
- bin/Debug/slngen/net5.0/runtimes/win/lib/netcoreapp3.0/System.Drawing.Common.dll
- bin/Debug/slngen/net5.0/runtimes/win/lib/netcoreapp3.0/System.Windows.Extensions.dll
- bin/Debug/slngen/net5.0/runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll
- bin/Debug/slngen/net5.0/slngen.deps.json
- bin/Debug/slngen/net5.0/slngen.dll
- bin/Debug/slngen/net5.0/slngen.exe
- bin/Debug/slngen/net5.0/slngen.runtimeconfig.json
- bin/Debug/slngen/net5.0/System.CodeDom.dll
- bin/Debug/slngen/net5.0/System.Configuration.ConfigurationManager.dll
- bin/Debug/slngen/net5.0/System.Diagnostics.PerformanceCounter.dll
- bin/Debug/slngen/net5.0/System.Drawing.Common.dll
- bin/Debug/slngen/net5.0/System.Management.dll
- bin/Debug/slngen/net5.0/System.Security.Cryptography.ProtectedData.dll
- bin/Debug/slngen/net5.0/System.Security.Permissions.dll
- bin/Debug/slngen/net5.0/System.Windows.Extensions.dll
- bin/Debug/slngen/net6.0/McMaster.Extensions.CommandLineUtils.dll
- bin/Debug/slngen/net6.0/Microsoft.Extensions.FileSystemGlobbing.dll
- bin/Debug/slngen/net6.0/Microsoft.VisualStudio.RemoteControl.dll
- bin/Debug/slngen/net6.0/Microsoft.VisualStudio.Setup.Configuration.Interop.dll
- bin/Debug/slngen/net6.0/Microsoft.VisualStudio.Telemetry.dll
- bin/Debug/slngen/net6.0/Microsoft.VisualStudio.Utilities.Internal.dll
- bin/Debug/slngen/net6.0/Microsoft.Win32.SystemEvents.dll
- bin/Debug/slngen/net6.0/Newtonsoft.Json.dll
- bin/Debug/slngen/net6.0/runtimes/unix/lib/netcoreapp3.0/System.Drawing.Common.dll
- bin/Debug/slngen/net6.0/runtimes/win/lib/netcoreapp2.0/System.Diagnostics.PerformanceCounter.dll
- bin/Debug/slngen/net6.0/runtimes/win/lib/netcoreapp2.0/System.Management.dll
- bin/Debug/slngen/net6.0/runtimes/win/lib/netcoreapp3.0/Microsoft.Win32.SystemEvents.dll
- bin/Debug/slngen/net6.0/runtimes/win/lib/netcoreapp3.0/System.Drawing.Common.dll
- bin/Debug/slngen/net6.0/runtimes/win/lib/netcoreapp3.0/System.Windows.Extensions.dll
- bin/Debug/slngen/net6.0/runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll
- bin/Debug/slngen/net6.0/slngen.deps.json
- bin/Debug/slngen/net6.0/slngen.dll
- bin/Debug/slngen/net6.0/slngen.exe
- bin/Debug/slngen/net6.0/slngen.runtimeconfig.json
- bin/Debug/slngen/net6.0/System.CodeDom.dll
- bin/Debug/slngen/net6.0/System.Configuration.ConfigurationManager.dll
- bin/Debug/slngen/net6.0/System.Diagnostics.PerformanceCounter.dll
- bin/Debug/slngen/net6.0/System.Drawing.Common.dll
- bin/Debug/slngen/net6.0/System.Management.dll
- bin/Debug/slngen/net6.0/System.Security.Cryptography.ProtectedData.dll
- bin/Debug/slngen/net6.0/System.Security.Permissions.dll
- bin/Debug/slngen/net6.0/System.Windows.Extensions.dll
- bin/Debug/slngen/netcoreapp3.1/McMaster.Extensions.CommandLineUtils.dll
- bin/Debug/slngen/netcoreapp3.1/Microsoft.Extensions.FileSystemGlobbing.dll
- bin/Debug/slngen/netcoreapp3.1/Microsoft.VisualStudio.RemoteControl.dll
- bin/Debug/slngen/netcoreapp3.1/Microsoft.VisualStudio.Setup.Configuration.Interop.dll
- bin/Debug/slngen/netcoreapp3.1/Microsoft.VisualStudio.Telemetry.dll
- bin/Debug/slngen/netcoreapp3.1/Microsoft.VisualStudio.Utilities.Internal.dll
- bin/Debug/slngen/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll
- bin/Debug/slngen/netcoreapp3.1/Newtonsoft.Json.dll
- bin/Debug/slngen/netcoreapp3.1/runtimes/unix/lib/netcoreapp3.0/System.Drawing.Common.dll
- bin/Debug/slngen/netcoreapp3.1/runtimes/win/lib/netcoreapp2.0/System.Diagnostics.PerformanceCounter.dll
- bin/Debug/slngen/netcoreapp3.1/runtimes/win/lib/netcoreapp2.0/System.Management.dll
- bin/Debug/slngen/netcoreapp3.1/runtimes/win/lib/netcoreapp3.0/Microsoft.Win32.SystemEvents.dll
- bin/Debug/slngen/netcoreapp3.1/runtimes/win/lib/netcoreapp3.0/System.Drawing.Common.dll
- bin/Debug/slngen/netcoreapp3.1/runtimes/win/lib/netcoreapp3.0/System.Windows.Extensions.dll
- bin/Debug/slngen/netcoreapp3.1/runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll
- bin/Debug/slngen/netcoreapp3.1/slngen.deps.json
- bin/Debug/slngen/netcoreapp3.1/slngen.dll
- bin/Debug/slngen/netcoreapp3.1/slngen.exe
- bin/Debug/slngen/netcoreapp3.1/slngen.runtimeconfig.json
- bin/Debug/slngen/netcoreapp3.1/System.CodeDom.dll
- bin/Debug/slngen/netcoreapp3.1/System.ComponentModel.Annotations.dll
- bin/Debug/slngen/netcoreapp3.1/System.Configuration.ConfigurationManager.dll
- bin/Debug/slngen/netcoreapp3.1/System.Diagnostics.PerformanceCounter.dll
- bin/Debug/slngen/netcoreapp3.1/System.Drawing.Common.dll
- bin/Debug/slngen/netcoreapp3.1/System.Management.dll
- bin/Debug/slngen/netcoreapp3.1/System.Security.Cryptography.ProtectedData.dll
- bin/Debug/slngen/netcoreapp3.1/System.Security.Permissions.dll
- bin/Debug/slngen/netcoreapp3.1/System.Windows.Extensions.dll
- Microsoft.VisualStudio.Setup.Configuration.Interop.dll
- ref/slngen.dll
- slngen.deps.json
- slngen.deps.json
- slngen.deps.json
- slngen.deps.json
- slngen.dll
- slngen.exe
- slngen.pdb
- slngen.runtimeconfig.dev.json
- slngen.runtimeconfig.dev.json
- slngen.runtimeconfig.dev.json
- slngen.runtimeconfig.json
- slngen.runtimeconfig.json
- slngen.runtimeconfig.json
- slngen.runtimeconfig.json
references:
- {NetCoreTargetingPackRoot}/Microsoft.NETCore.App.Ref/5.0.0/ref/net5.0/Microsoft.CSharp.dll
Expand Down
38 changes: 22 additions & 16 deletions src/Microsoft.VisualStudio.SlnGen.UnitTests/SlnProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,26 @@ public void SolutionItems()
logger.LowImportanceMessages.ShouldBeEmpty();
}

[Fact]
public void UseAssemblyNameProperty()
[Theory]
[InlineData(null)]
[InlineData("SomeProject")]
public void ProjectNameIsCorrect(string projectName)
{
CreateAndValidateProject(expectedGuid: "{3EA7B89C-F85F-49F4-B99D-1BC184C08186}", expectedName: "Project.Name");
Dictionary<string, string> globalProperties = new Dictionary<string, string>
{
[MSBuildPropertyNames.SlnGenProjectName] = projectName ?? string.Empty,
};

SlnProject project = CreateAndValidateProject(expectedGuid: "{3EA7B89C-F85F-49F4-B99D-1BC184C08186}", globalProperties: globalProperties);

if (!string.IsNullOrWhiteSpace(projectName))
{
project.Name.ShouldBe(projectName);
}
else
{
project.Name.ShouldBe(Path.GetFileNameWithoutExtension(project.FullPath));
}
}

[Fact]
Expand Down Expand Up @@ -350,7 +366,7 @@ private static void ValidateParseCustomProjectTypeGuids(Project project, string
actualProjectTypeGuid.Value.ShouldBe(expectedProjectTypeGuid);
}

private SlnProject CreateAndValidateProject(bool isMainProject = false, string expectedGuid = null, string expectedName = null, string extension = ProjectFileExtensions.CSharp, IDictionary<string, string> globalProperties = null, string isDeployable = null)
private SlnProject CreateAndValidateProject(bool isMainProject = false, string expectedGuid = null, string extension = ProjectFileExtensions.CSharp, IDictionary<string, string> globalProperties = null, string isDeployable = null)
{
if (!isDeployable.IsNullOrWhiteSpace())
{
Expand All @@ -359,17 +375,12 @@ private SlnProject CreateAndValidateProject(bool isMainProject = false, string e
globalProperties[MSBuildPropertyNames.SlnGenIsDeployable] = isDeployable;
}

Project expectedProject = CreateProject(expectedGuid, expectedName, extension, globalProperties);
Project expectedProject = CreateProject(expectedGuid, extension, globalProperties);

SlnProject actualProject = SlnProject.FromProject(expectedProject, new Dictionary<string, Guid>(), isMainProject);

actualProject.FullPath.ShouldBe(expectedProject.FullPath);

if (!expectedName.IsNullOrWhiteSpace())
{
actualProject.Name.ShouldBe(expectedName);
}

if (expectedGuid != null)
{
actualProject.ProjectGuid.ToSolutionString().ShouldBe(expectedGuid);
Expand All @@ -380,7 +391,7 @@ private SlnProject CreateAndValidateProject(bool isMainProject = false, string e
return actualProject;
}

private Project CreateProject(string projectGuid = null, string name = null, string extension = ProjectFileExtensions.CSharp, IDictionary<string, string> globalProperties = null)
private Project CreateProject(string projectGuid = null, string extension = ProjectFileExtensions.CSharp, IDictionary<string, string> globalProperties = null)
{
string fullPath = GetTempFileName(extension);

Expand All @@ -391,11 +402,6 @@ private Project CreateProject(string projectGuid = null, string name = null, str
globalProperties[MSBuildPropertyNames.ProjectGuid] = projectGuid;
}

if (!name.IsNullOrWhiteSpace())
{
globalProperties[MSBuildPropertyNames.AssemblyName] = name;
}

return MockProject.Create(fullPath, globalProperties);
}
}
Expand Down
Loading