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

Support multiple edmx files in the same project. #5

Open
malylemire1 opened this issue May 19, 2022 · 2 comments
Open

Support multiple edmx files in the same project. #5

malylemire1 opened this issue May 19, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@malylemire1
Copy link

malylemire1 commented May 19, 2022

Support multiple edmx files in the same project.

image

  • The Task need to be updated for multiple Input and Output files.
  • The Target need to handle the multiple output files.
@CZEMacLeod
Copy link
Owner

@malylemire1 I've been looking at adding some features to this package to cover scenarios like this one.
Unfortunately, there are some other improvements I need to do first, mainly around replacing the converted t4 templates code that currently generates the code with a CodeDomProvider / roslyn based version that is (mostly) language agnostic.
After that it will be much easier to adjust the behaviour of the task. The current version is a MVP, converting the old EF PowerTools feature and code.

Generally, I keep multiple DbContexts, their migrations and the edmx / views in separate projects, and then just include them into my main project, so the issue you are coming across doesn't happen.

You could manually call the custom MSBuild task multiple times from a custom target in your project, and pass in each view.

Untested:

<PropertyGroup>
	<CompileDependsOn>CustomEF6Views;$(CompileDependsOn)</CompileDependsOn>
</PropertyGroup>

<Target Name="CustomEF6Views">
	<MakeDir Directories="$(EntityFramework6GenerateViewsOutputDir)" ContinueOnError="true" />
	<ItemGroup>
		<_EntityViewCompile Remove="@(_EntityViewCompile)" />
		<_Temporary Remove="@(_Temporary)" />
		<_Temporary Include="EDMX\First.edmx">
			<CustomToolNamespace>MMBS.EntityFramework.First</CustomToolNamespace>
		</_Temporary>
	</ItemGroup>
	<C3D.MSBuild.Tools.EF6.Tasks.GenerateViews
	  SourceFiles="@(_Temporary)"
	  OutputDirectory="$(EntityFramework6GenerateViewsOutputDir)"
	  AssemblyName="$(AssemblyName)"
	  Language="$(Language)"
	  DefaultNamespace="$(RootNamespace)"
	  Debug="$(EntityFramework6GenerateViewsDebug)">
		<Output TaskParameter="OutputFile" ItemName="_EntityViewCompile" />
	</C3D.MSBuild.Tools.EF6.Tasks.GenerateViews>
	<ItemGroup>
		<_Temporary Remove="@(_Temporary)" />
		<_Temporary Include="EDMX\Second.edmx">
			<CustomToolNamespace>MMBS.EntityFramework.Second</CustomToolNamespace>
		</_Temporary>
	</ItemGroup>
	<C3D.MSBuild.Tools.EF6.Tasks.GenerateViews
	  SourceFiles="@(_Temporary)"
	  OutputDirectory="$(EntityFramework6GenerateViewsOutputDir)"
	  AssemblyName="$(AssemblyName)"
	  Language="$(Language)"
	  DefaultNamespace="$(RootNamespace)"
	  Debug="$(EntityFramework6GenerateViewsDebug)">
		<Output TaskParameter="OutputFile" ItemName="_EntityViewCompile" />
	</C3D.MSBuild.Tools.EF6.Tasks.GenerateViews>
	<ItemGroup>
		<Compile Include="@(_EntityViewCompile)" Condition="EXISTS('%(FullPath)')" />
		<FileWrites Include="@(_EntityViewCompile)" Condition="EXISTS('%(FullPath)')" />
	</ItemGroup>	
</Target>

@CZEMacLeod CZEMacLeod self-assigned this May 20, 2022
@CZEMacLeod CZEMacLeod added the enhancement New feature or request label May 20, 2022
@malylemire1
Copy link
Author

malylemire1 commented May 24, 2022

Hi,

I have managed to make it work with a simple change

<EntityViews Include="EDMX\First.edmx">
      <CustomToolNamespace>MMBS.EntityFramework.First</CustomToolNamespace>
</EntityViews>
<EntityViews Include="EDMX\Second.edmx">
      <CustomToolNamespace>MMBS.EntityFramework.Second</CustomToolNamespace>
 </EntityViews>

<Target Name="EntityFramework6GenerateMultipleViewsTarget" BeforeTargets="BeforeCompile" Condition="'@(EntityViews)'!=''">
		<Message Text="EntityViews: %(EntityViews.Identity)" Importance="high" />
		<MakeDir Directories="$(EntityFramework6GenerateViewsOutputDir)" ContinueOnError="true" />
		<C3D.MSBuild.Tools.EF6.Tasks.GenerateViews
		  SourceFiles="@(EntityViews)"
		  OutputDirectory="$(EntityFramework6GenerateViewsOutputDir)"
		  AssemblyName="$(AssemblyName)"
		  Language="$(Language)"
		  DefaultNamespace="%(EntityViews.CustomToolNamespace)"
		  Debug="$(EntityFramework6GenerateViewsDebug)">
		  <Output TaskParameter="OutputFile" ItemName="_EntityViewCompile" />
		</C3D.MSBuild.Tools.EF6.Tasks.GenerateViews>
		<Message Text="%(_EntityViewCompile.Identity)" Importance="high" />
		<ItemGroup>
			<Compile Include="@(_EntityViewCompile)" Condition="EXISTS('%(FullPath)')" />
			<FileWrites Include="@(_EntityViewCompile)" Condition="EXISTS('%(FullPath)')" />
		</ItemGroup>
</Target>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants