Suppose you're moving files between projects and you have to move a Settings or Resource File. If you drag these files between projects, you’ll notice that Visual Studio doesn’t preserve the relationships between the designer files:
Since these are embedded resources, you’ll need a few extra steps to get things sorted out:
- Right-click on the Project and choose Unload Project. Visual Studio may churn for a few seconds.
- Once unloaded, Right-click on the project file and choose Edit <Project-Name>.
- Locate your resource files and setup them up to be embedded resources with auto-generated designer files:
<ItemGroup> <None Include="Resources\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> <LastGenOutput>Settings.Designer.cs</LastGenOutput> </None> <Compile Include="Resources\Settings.Designer.cs"> <AutoGen>True</AutoGen> <DependentUpon>Settings.settings</DependentUpon> <DesignTimeSharedInput>True</DesignTimeSharedInput> </Compile> <EmbeddedResource Include="Resources\Resources.resx"> <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.cs</LastGenOutput> </EmbeddedResource> <Compile Include="Resources\Resources.Designer.cs"> <AutoGen>True</AutoGen> <DependentUpon>Resources.resx</DependentUpon> <DesignTime>True</DesignTime> </Compile> </ItemGroup>
Cheers.
I think the correct way would be to include only the .resx file, set the file properties and let the VS regenerate the .designer.cs file automatically.
ReplyDeleteSure, that works too. But you'll end up with Settings1.Designer.cs in source control.
ReplyDelete