VS Setup Project target app.config in ..obj\x86\Release - visual-studio-2010

I created an app.config transform for my WinForms project using Dan Abramov's solution here. Works great and the config file is transformed and present in the correct obj folder.
When I look at the outputs for the Primary Output of my application, it gets the app.config from the project directory instead of the corresponding obj folder like everything else...a big oversight, in my opinion, by MSFT. Obviously, they didn't have transforms in mind for all config file types.
So now, how do I get the Primary Output of my main project to output the config file from the obj folder based on the build configuration?

Have you tried using SlowCheetah (a VS extension) which enables you to transform app.config in the same way that web.config works. Also your scenario for transforming app.config for a setup project is supported.

I found the work around I was looking for here. Scroll to the bottom and see kakoskin's answer. In conjunction with Dan Abramov's solution, I was able to get the results I was looking for. Here's the MSBuild code I used:
<Target Name="AfterBuild" Condition="exists('app.$(Configuration).config')">
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
<TransformXml Source="App.config" Transform="app.$(Configuration).config" Destination="App.Transformed.config" />
The <ItemGroup> section will remove the app.config file from the corresponding obj\ folder and replace it with the transformed config file, which is not needed but I left it in there anyways.
Hope this helps others out as well!

Related

How do I remove visual assets from UWP projects

I'm using Visual Studio 2017. I used the asset generator to auto-generate icons for my app, but most of them look very bad. So, I thought to cut down on the number of icons, but now I can't find any option to remove an image from the Visual Assets listing. only adding/auto-generating them. Opening the associated Package.appxmanifest file doesn't show any of these images being even referenced. And without solving this problem, Visual Studio is not letting me even build the project >_<
So, I'd like to understand how to remove some of these images? Searching the microsoft forums, but haven't yet found anything related to "removing" assets,
Just delete the path to the file, ie Assets\SmallTile.png in Package.appxmanifest.
You cannot however remove all the assets since some sizes like splash screen or medium tile are required - you'll have to generate/add new.
Also make sure that these checkboxes are not checked for icons you've removed.
You need to undo in 3 steps:
Remove the Logo settings from Package.appxmanifest, but leave the required ones.
Open Assets folder, delete all auto-generated assets, again, leave the required ones.
Close your project, and open your .csproj file in notepad, delete the newly added referenced items - they look like below, and then save the csproj file.
<ItemGroup>
<Content Include="Assets\LargeTile.scale-100.png" />
<Content Include="Assets\LargeTile.scale-125.png" />
<Content Include="Assets\LargeTile.scale-150.png" />
<Content Include="Assets\LargeTile.scale-200.png" />
<Content Include="Assets\LargeTile.scale-400.png" />
<Content Include="Assets\SmallTile.scale-100.png" />
<Content Include="Assets\SmallTile.scale-125.png" />
<Content Include="Assets\SmallTile.scale-150.png" />
...

Why is separate resource file generated after saving?

Before modifying a resource file, it looks like this in VS.NET (2013):
Strings.resx
Strings.Designer.cs
After saving, it looks like this:
Strings.resx
Strings.Designer.cs
Strings1.Designer.cs
If I try to run the project, I get an error that Strings already exist. I have to then delete Strings.Designer.cs and rename Strings1.Designer.cs to Strings.Designer.cs.
Then I have to unload the project and modify those references in the project file XML. Then reload and all is well until I modify again.
Any idea how to fix this?
I faced the same issue. I deleted my old resource file and created a new resource file with same name and content. Now it is working fine.
So, delete the Strings.resx file and create a new file with the same name that is Strings.resx
I found the answer from this link Generating *.Designer.cs from .resx.
Basically, you need to:
Right-click on your project and click Unload.
Then right-click again and click on Edit on your project.
Find the string <LastGenOutput> and change the entry to whatever you want.
For example, I need to generate Strings.Designer.cs:
<ItemGroup>
<Compile Update="App_GlobalResources\Strings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="App_GlobalResources\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
I hope this post can help someone in the future.
Cheers

Slow Cheetah not working in when building

I have added Cheeatah to simplify managing my configuration.
I can see the changes in the Preview. But when I look at the config when I build I dont see it transforming my config file. I have selected the configuration and click build. Am I missing something
Make sure the configuration file reference in the project file as the TransformOnBuild node with a value of True, below is an example:
<None Include="App.config">
<TransformOnBuild>True</TransformOnBuild>
</None>
Unlike Kieron's answer, in my situation, <TransformOnBuild> was only set for Designer. Just had to delete that condition:
<None Include="App.config">
<SubType>Designer</SubType>
<TransformOnBuild>true</TransformOnBuild>
</None>
An other situation in which the same error occurs:
<Content Include="Castle.Config.Xml">
<TransformOnBuild>true</TransformOnBuild>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Problem: TransformOnBuild vs CopyToOutputDirectory!
"TransformOnBuild" is a implicit "CopyToOutputDirectory". If you define both, first the transformation is done, then "copy" overrides you transformed file.
This situation in our project happend cause a developer has set the copy tag accidentially. It seems, that the order was not in all situations the same. Removing the CopyToOutputDirectory solves this problem.
This version works as expected:
<Content Include="Castle.Config.Xml">
<TransformOnBuild>true</TransformOnBuild>
</Content>

Resources files issues in ASP.NET MVC 3

I´m having a strange problem with resources files. Strange because it was working great.
Well, I have some resources files. I created a Resources folder on my asp.net mvc 3 project structure and I am mirroring the views's folder structure. For now I have:
Views
Shared
_Layout.cshtml
Resources
Shared
Layout.pt-BR.resx
Layout.en-US.resx
Layout.ko-KR.resx
All resources files are configured as Embedded Resource, PublicResXFileCodeGenerator and with Custom Tool Namespace "ViewRes". All ".Designer.cs" files are empty. I remember to see some code in them when it was working.
On my .csproj file I have these data:
<ItemGroup>
<EmbeddedResource Include="Resources\Shared\Layout.en-US.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Layout.en-US.Designer.cs</LastGenOutput>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Shared\Layout.ko-KR.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
<LastGenOutput>Layout.ko-KR.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Shared\Layout.pt-BR.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Layout.pt-BR.Designer.cs</LastGenOutput>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
The problem is: When I try to access the #ViewRes on my views, It is not recognized. I tried already to remove the custom tool namespace but the #Resource is not recognized too. In both situations I got this compilation error:
Compiler Error Message: CS0103: The name 'ViewRes' does not exist in the current context
Does anybody have any idea?
Thanks,
Paulo
EDIT: NEW INFORMATIONS
I created a global Resources.resx file by project's properties menu in VS2010 and it's working with the custom tool namespaces I have entered. "Resources" namespace still not working. I think the problem is with the local resources files. Unfortunatly I need them because I can't rename the global resources.resx file including the culture code.
EDIT 2
I created new .resx file on Resource folder and what I can see is that the filename can not have 2 ".". Is the name is Resources.resx, it works. If the name is Resource-en-US.resx, it works but, If the name is Resources.en-US.resx it fails!
I think you can also write a custom helper, that will return by reflection the string.

WinForm partial classes

I have a WinForm project that contains a form called MainUI. You can see that the automatically generated partial class shows up as a node under MainUI.cs. Is there a way to "move" my self created partial class MainUI.Other.cs under MainUI.cs so that it'll show as another node?
Close the solution in Visual Studio, and open your .csproj file in a text editor. Find MainUI.Other.cs, and add the following XML element:
<Compile Include="MainUI.Other.cs">
<SubType>Form</SubType>
<DependentUpon>MainUI.cs</DependentUpon> <!-- this is the magic incantation -->
</Compile>
Reopen the solution in Visual Studio and enjoy subnodular goodness.
That said, you may want to reconsider whether this is a good idea. The reason the .designer.cs file is displayed as a subnode is because you won't normally need or want to open it, because it contains generated code which you'd normally view or edit through the designer. Whereas a partial class file will contain your code, that you'll want to edit and view; it may be confusing to maintenance programmers if the file is not easily visible in Solution Explorer. However, only you can know what's right for your project -- just something to bear in mind!
Yes, this is possible, but you will have to hand edit the project file.
In the project file (open it with the XML Editor) locate the file listing item group. In my example, I left the form as "Form1.cs". Add the child element "<DependentUpon>" to your extended class as per the example below:
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Form1.Designer.Other.cs">
<DependentUpon>Form1.cs</DependentUpon>
<SubType>Form</SubType>
</Compile>
Typically though you wouldn't want any non-generated code to be hidden as a child node though. My normal practice is to create a folder in the project called "Partial Classes" and add them all in the same location.
You can modify the project source file to group the related files.
In the project source file, find ItemGroup element which contains MainUI.cs and add an entry for MainUI.Others.cs
Here a blog post showing how to do it in details.
Group/nest source code files
Just to add to #itowlson's answer: if you're getting an error such as "Duplicate 'Compile' items were included." when compiling, that's probably because the files you're telling it to include are already included using a wild card.
The solution is to remove then add them to the compile config like so:
</Project>
<ItemGroup>
<Compile Remove="MainUI.Other1.cs" />
<Compile Remove="MainUI.Other2.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainUI.Other1.cs">
<DependentUpon>MainUI.cs</DependentUpon>
</Compile>
<Compile Include="MainUI.Other2.cs">
<DependentUpon>MainUI.cs</DependentUpon>
</Compile>
</ItemGroup>
</Project>

Resources