How to combine App.config files to have expandable folder like structure - c#

In an existing C# WPF solution I can see the app.config and app.release.config files are combined in a folder like structure:
However in my new solution I cannot duplicate this functionality and get this instead:
This is clearly less appealing and takes up a lot of space in the solution explorer. How can I combine my config files to have a folder-like structure?
*note:
I posted this Q/A because I was unable to find anything regarding this issue until I already had the solution and knew exactly what to search for.. After that I found a few similar questions like this one: In Visual Studio (2008) is there a way to have a custom dependent file on another custom file?. Hopefully this helps someone else find the answer quicker than I did.

After lots of file comparisons I found the key in the project file (ProjectName.csproj). To achieve the desired structure you have to make the child configs dependant on the original. Similar to how views have dependant code files.
Change:
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="App.Production.config" />
<None Include="App.DR.config" />
<None Include="App.INTLiberty.config" />
<None Include="App.Release.config" />
<None Include="App.UAT.config" />
<None Include="App.Training.config" />
<None Include="App.QAProd.config" />
<None Include="App.INTOvation.config" />
<None Include="App.QA.config" />
<None Include="App.QAEnv3.config" />
<None Include="App.QAEnv2.config" />
<None Include="App.QAEnv1.config" />
<None Include="App.Development.config" />
<None Include="App.Debug.config" />
</ItemGroup>
To:
<ItemGroup>
<None Include="App.Production.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.DR.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.INTLiberty.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.Release.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.UAT.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.Training.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.QAProd.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.INTOvation.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.QA.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.QAEnv3.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.QAEnv2.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.QAEnv1.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.Development.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.Debug.config" >
<DependentUpon>App.config</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>

I agree with the easiest solution (editing project file) by RyanS to solve this problem. Sometime back I went through similar situation and solved like this. Hope this helps someone.
1) We can easily add transformation configs to web.config just by clicking "Add Config Transform" menu item.
This will add only number of solution configurations available. If you want to add more transformation configs then you need to add new configurations first. In this below case it will create only two transformations (Debug & Release)
2) Coming to App.config, one will not see this "Add Transform" menu item. Install SlowCheetah plugin and that will add this menu item and then follow step 1.

Related

Trying to clean specflow BDD test error: Test assembly not found. Please build the project to enable the SpecFlow Visual Studio Extension features

I currently training on how to Specflow with C#. I made a few changes to my test saved them. I then performed a 'clean' at project level and got the following error message.
Severity Code Description Project File Line Suppression State
Warning Test assembly not found. Please build the project to enable the SpecFlow Visual Studio Extension features.
0
and this
Severity Code Description Project File Line Suppression State
Error IDE1100 Error reading content of source file 'C:\Users\myname\source\repos\UdemyTrainingProject\UdemyTrainingProject\obj\Debug\net6.0\UdemyTrainingProject.AssemblyInfo.cs' -- 'Could not find file 'C:\Users\myname\source\repos\UdemyTrainingProject\UdemyTrainingProject\obj\Debug\net6.0\UdemyTrainingProject.AssemblyInfo.cs'.'. UdemyTrainingProject C:\Users\myname\source\repos\UdemyTrainingProject\UdemyTrainingProject\obj\Debug\net6.0\UdemyTrainingProject.AssemblyInfo.cs 1 Active
Csprog file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Selenium.Firefox.WebDriver" Version="0.27.0" />
<PackageReference Include="Selenium.Support" Version="4.4.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.4.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="105.0.5195.5200" />
<PackageReference Include="Selenium.WebDriver.MicrosoftDriver" Version="17.17134.0" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.74" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
</ItemGroup>
<ItemGroup>
<Folder Include="Features\" />
<Folder Include="Utilities\" />
</ItemGroup>
<ItemGroup>
please watch this video
So I was able to resolve the issue.
Go to the top menu > select project> Build> build solution
the build is successful go to step 3
The Go into the search box with the spy glass logo and type 'test explorer'
In test explorer you have the choice of 2 ways to run:
the small green triangle will run ALL tests
the large green triangle will your chosen test only.
Select from option 4 and run your test.

Create an alias for multiple items in a csproj

I have several items that should be removed from Content, Compile, and EmbeddedResource.
I do this like this now:
<Content Remove="data\**" />
<Content Remove="other\**" />
<Content Remove="etc\**" />
<Compile Remove="data\**" />
<Compile Remove="other\**" />
<Compile Remove="etc\**" />
<EmbeddedResource Remove="data\**" />
<EmbeddedResource Remove="other\**" />
<EmbeddedResource Remove="etc\**" />
This works, but bloats the project file significantly. Ideally, I'd like to create something like:
<RemoveAll Include="data\**" />
... some magic that checks RemoveAll and
emits Content, Compile and EmbeddedResource for all RemoveAlls
...
Is this possible in csproj? I've already experimented a bit with targets, but I couldn't get a target to remove these items.
The only approach I'm aware of would be:
<ItemGroup>
<RemoveMe Include="data\**" />
<RemoveMe Include="other\**" />
<RemoveMe Include="etc\**" />
<None Remove="#(RemoveMe)" />
<Compile Remove="#(RemoveMe)" />
<EmbeddedResource Remove="#(RemoveMe)" />
</ItemGroup>
I've already experimented a bit with targets, but I couldn't get a target to remove these items.
Note that removing items in targets will not remove them from Solution Explorer in Visual Studio. The view of the project in SE comes from evaluation, where no targets are executed.

Blazor not discovering new pages in subfolders

I create a new page, e.g. in Pages/Clients/ subfolder with following code:
#page "/clients"
#inject NavigationManager NavigationManager
<div>My clients page</div>
I put the link:
<NavLink href="/clients" class="nav-link">Clients</NavLink>
When I click on link the page shows me default message
Sorry, there's nothing at this address.
Then I stop the app. Put my clients page in "Pages" folder. Run the application and I see the proper page with
My clients page
Ok, then I move my page file again to Pages/Clients/ subfolder, run the app and... it still works! Moreover - If I do any changes to Clients.razor page it is being shown correctly in browser.
So it looks like Blazor cannot find the page in subfolder for the first time, but after it "registers" it somehow it could find and show it correctly all the time.
I have the
<base href="~/" />
line in my _Host.cshtml file
Well, I was fighting with it for a couple of days and right after posting on Stackoverflow I accidentally found an answer.
In your .csproj file there were following lines:
<ItemGroup>
<Watch Include="**\*.razor" />
</ItemGroup>
<ItemGroup>
<Content Remove="Pages\Activities\ActivitiesList.razor" />
<Content Remove="Pages\Entrance\Entrance.razor" />
<Content Remove="Pages\Instructors\InstructorsList.razor" />
<Content Remove="Pages\Plan\Plan.razor" />
</ItemGroup>
<ItemGroup>
<None Include="Pages\Activities\ActivitiesList.razor" />
<None Include="Pages\Administration\Administration.razor" />
<None Include="Pages\Entrance\Entrance.razor" />
<None Include="Pages\Instructors\InstructorsList.razor" />
<None Include="Pages\Plan\Plan.razor" />
</ItemGroup>
<ItemGroup>
<Watch Remove="Pages\Activities\ActivitiesList.razor" />
<Watch Remove="Pages\Administration\Administration.razor" />
<Watch Remove="Pages\Entrance\Entrance.razor" />
<Watch Remove="Pages\Instructors\InstructorsList.razor" />
<Watch Remove="Pages\Plan\Plan.razor" />
</ItemGroup>
I removed most of them and left only this:
<ItemGroup>
<Watch Include="**\*.razor" />
</ItemGroup>
All the files are being now discovered correctly. Just remember to check your csproj if some garbage aren't being generated there during development process.

C# project file - Why doesn't it represent what's in my project?

I am trying to understand the contents of a .csproj file after I converted from PCL to a .NET shared. Here is an example and some questions:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.583944" />
<PackageReference Include="sqlite-net-pcl" Version="1.4.118" />
<PackageReference Include="Syncfusion.Xamarin.SfChart" Version="16.2.0.42" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\" />
<Folder Include="Views\Settings\Pages\" />
<Folder Include="Views\Home\PopUp\" />
<Folder Include="Views\Help\Cards\" />
</ItemGroup>
Can someone explain to me why only certain folders appear above even though my project has many more folders
<ItemGroup>
<EmbeddedResource Remove="Views\Cards\Category\CategoriesPage.xaml" />
<EmbeddedResource Remove="Views\Cards\Templates\LinkTextCell.xaml" />
<EmbeddedResource Remove="Views\Cards\Templates\SwitchViewCell.xaml" />
<EmbeddedResource Remove="Views\Home\Dictionary.xaml" />
</ItemGroup>
Can someone explain what all these Remove lines do / mean?
<ItemGroup>
<None Include="Views\Cards\Cards.xaml" />
<None Include="Views\Cards\Category\CategoriesPage.xaml" />
<None Include="Views\Cards\Category\CategoryViewCell.xaml" />
<None Include="Views\Cards\Templates\LinkTextCell.xaml" />
<None Include="Views\Cards\Templates\SwitchViewCell.xaml" />
<None Include="Views\MainPage.xaml" />
<None Include="Views\MainPage.xaml" />
<None Include="Views\MainPage.xaml" />
<None Include="Views\MainPage.xaml" />
</ItemGroup>
Can someone explain why the MainPage might appear four times? Is it needed more than once, is it needed at all? There are many files that are not in the list of Includes? If only half are there then why is it?
<ItemGroup>
<Compile Update="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\Home\HomePage.xaml.cs">
<DependentUpon>HomePage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\Cards\Category\CategoryViewCell.xaml.cs">
<DependentUpon>CategoryViewCell.xaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
I understand that some views depend on others but I have many more of these and yet it only shows the relationship for three. Why could this be?
Can I just remove all these entries from the project file as there seems to be not much similarity between the project file and the folders / files in the project?
The new .csproj format has some basic changes to simplify the file. Now by default all .cs (or .vb if you're doing VB.Net) files are included. See here for more information.
The reason your file is explicitly including some files and folders is because you've probably edited the file properties at some point.
The Remove lines are there to allow files to be part of your project structure but not compiled or embedded automatically.
As for why MainPage.xaml appears multiple times, I have no idea. Either a bug in Visual Studio has added them, or perhaps a source control merge conflict. Either way, those duplicate lines are redundant and can be removed.

Xamarin / Mono can't find System.Core

I have a test project under Xamarin that when I try to run it it tells me it can't load System.Core though from the screen shot it is clear that System.Core is one of the references.
What Might be the error here?
(open the image in a new tab to see it in full detail)
It seems the problem is with my primary project not the test project. When
I looked at all the references they were red. So I deleted them and tried
to add them again but there are no references to add. See the image below.
The following edits to the .csproj file fixed the problem
--- a/SketchSolveC#/SketchSolveC#.csproj
+++ b/SketchSolveC#/SketchSolveC#.csproj
## -6,12 +6,9 ##
<ProductVersion>12.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{46D849FA-8E4B-4656-B494-290697EBD9EC}</ProjectGuid>
- <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>SketchSolveC</RootNamespace>
<AssemblyName>SketchSolveC#</AssemblyName>
- <TargetFrameworkProfile>Profile1</TargetFrameworkProfile>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
## -30,15 +27,13 ##
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Xml" />
- <Reference Include="System.Core" />
- </ItemGroup>
- <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SketchSolve.cs" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Data.Linq" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
</ItemGroup>
- <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
## -49,4 +44,4 ##
</Properties>
</MonoDevelop>
</ProjectExtensions>
-</Project>
\ No newline at end of file
+</Project>

Categories