What I do
I have multiple tt files in my project file.
Therefore, many entries are created for each file as follows.
<ItemGroup>
<Compile Update="Sample.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Sample.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Sample.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Sample.cs</LastGenOutput>
</None>
</ItemGroup>
I want to prevent making this entry for every tt file.
What I have tried
The following statements were made using wildcards.
<ItemGroup>
<Compile Update="**/*.tt.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
<None Update="**/*.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>%(Filename).tt.cs</LastGenOutput>
</None>
</ItemGroup>
The following settings are used in the tt file.
<## output extension="tt.cs" #>
Problem
T4 works, but when I save the tt file, the following entry is added to csproj.
<ItemGroup>
<Compile Update="Sample.tt.cs">
<DesignTime>True</DesignTime>
</Compile>
</ItemGroup>
Question
How can I prevent entries from being added?
We can see the description of Update from this page
Enables you to modify metadata of an item; typically used to override
the default metadata of specific items after a group of items is
intially specified (such as with a wildcard).
Update overrides Compile when save the tt file, so this code will be added to scproj. This doesn't seem to prevent.
<ItemGroup>
<Compile Update="Sample.tt.cs">
<DesignTime>True</DesignTime>
</Compile>
</ItemGroup>
Related
I have a .NET solution with the projects below:
Console: Console .NET Core 2.2
Domain: .NET Standard 2.0
Domain.Tests: Console .NET Core 2.2 (XUnit)
Infrastructure: .NET Standard 2.0
My Domain.Tests.fsproj is defined as:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FsCheck" Version="3.0.0-alpha4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="Dsl.fs" />
<Compile Include="OpenAccountTests.fs" />
<Compile Include="CloseAccountTests.fs" />
<Compile Include="DepositCashTests.fs" />
<Compile Include="WithdrawCashTests.fs" />
<Compile Include="WireMoneyTests.fs" />
<Compile Include="RequestAddressChangeTests.fs" />
<Compile Include="RequestEmailChangeTests.fs" />
<Compile Include="RequestPhoneNumberChangeTests.fs" />
<Compile Include="ValidateAddressChangeTests.fs" />
<Compile Include="ValidateEmailChangeTests.fs" />
<Compile Include="ValidatePhoneNumberChangeTests.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.fsproj" />
</ItemGroup>
</Project>
But when compiling the solution I have the following warning:
ValidatePhoneNumberChangeTests.fs(102, 35): [FS0988] Main module of program is empty: nothing will happen when it is run
I checked that answer on SO and adding do() at the end of the last file of Domain.Tests: ValidatePhoneNumberChangeTests.fs didn't do anything.
What can I do to get rid of this warning?
#rmunn is on the right track in the comments. <OutputType> defaults to Library when TargetFramework is netstandardXX or net4XX, and Exe when TargetFramework is netcoreappXX.
Setting <OutputType>Library</OutputType> is IMO the best way to fix this, rather than adding an entry point that won't be called.
<TargetFramework>netcoreapp2.2</TargetFramework>
This specifies the Domain.Tests project as an executable
If you only need it to be a class library then change it to
<TargetFramework>netstandard2.0</TargetFramework>
If you simply want to remove the warning you can add a main method by either adding this at the end of ValidatePhoneNumberChangeTests.fs or in a Program.fs at the end of the compilation order
[<EntryPoint>]
let main argv =
0
Just remove the Program.fs and OutputType (it doesn't work for me as well). Set GenerateProgramFile to true in PropertyGroup like that:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>true</GenerateProgramFile>
</PropertyGroup>
cheers!
Every time I build my .NET Core project, it adds a deeper folder containing the .csproj file in \bin\release. The result is the following folder structure:
D:\home>
D:\home\site>
D:\home\site\repository>
D:\home\site\repository\bin>
D:\home\site\repository\bin\Release>
D:\home\site\repository\bin\Release\netcoreapp2.1>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release>
This keeps on growing when more builds are executed.
In Visual Studio, cleaning and rebuilding helps solve it. After a few builds the filename becomes too long, raising an error when trying to run the application.
At first, it did not really matter, but when deploying the WebApp-Bot to Azure, the same happens. The problem is that I have no option to remove the excessive files from the server. Which is why I need to stop it from happening at all.
The .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<UserSecretsId>SOME_USER_SECRETS_ID</UserSecretsId>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Compile Remove="%2a%2a\**" />
<Content Remove="%2a%2a\**" />
<EmbeddedResource Remove="%2a%2a\**" />
<None Remove="%2a%2a\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Gremlin.Net" Version="3.4.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.4.3" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.4.3" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.4.3" />
<PackageReference Include="Microsoft.Recognizers.Text.DataTypes.TimexExpression" Version="1.1.6" />
</ItemGroup>
<Import Project="PostDeployScripts\IncludeSources.targets" Condition="Exists('PostDeployScripts\IncludeSources.targets')" />
<Import Project="..\PostDeployScripts\IncludeSources.targets" Condition="Exists('..\PostDeployScripts\IncludeSources.targets')" />
<ItemGroup>
<None Remove="%2a%2a\%2a.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="bin\" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties Properties_4launchSettings_1json__JSONSchema="" /></VisualStudio></ProjectExtensions>
</Project>
The includesources.targets, which I see now has the always flag:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Update="**\*.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<None Include="**\*.csproj" >
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="PostDeployScripts\*.*" >
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
I would like to know why this happens and how to stop it, all help is welcome.
Your includesources.targets file has this little gem in it:
<Compile Update="**\*.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
Which would, if I understand correctly, cause the .cs files to be copied to your output folder. The next time a build is triggered, these files will probably also be compiled, creating a new bin\Release\netcoreapp2.1 from that location.
I'm not entirely sure what the targets file is there for, but I am pretty sure it's causing this issue. Try removing the file and the references to it from your .csproj, rebuild your project and see if you can deploy the bot.
I am unable to publish my Azure Functions (v1) Project after upgraded to VisualStudio 15.7.0 Preview 6.0 I get this error when click Publish button
C:\Program
Files\dotnet\sdk\2.1.200-preview-007597\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(167,5): error
: Assets file 'C:\Users\tonyv\source\repos\SistemaMulti\WebAPI\obj\project.assets.json'
doesn't have a target for '.NETFramework,Version=v4.6.1/win'. Ensure you have restored this project for TargetFrameworks 'net461'
Maybe you also need to include 'win' on RuntimeIdentifiers of yout project.
[C:\Users\tonyv\source\repos\SistemaMulti\WebAPI\WebAPI.csproj]
My .csproj is:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="MercadoPago\Pessoa.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.13" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="MercadoPago\" />
</ItemGroup>
</Project>
How to fix this?
The issue is that the following property is getting set in the publish profile (under Properties\Publish Profiles\<profilename>.pubxml)
<RuntimeIdentifier>win</RuntimeIdentifier>
Removing this property from the publishprofile should fix the issue.
There is a github thread for the same issue - https://github.com/Azure/Azure-Functions/issues/571
The workaround recommended there is:
Update this line in Properties\PublishProfiles\.pubxml (Remove the space in Any CPU).
<LastUsedPlatform>AnyCPU</LastUsedPlatform>
(Updating the profile from profile settings UI may re-add the space. Please remove it after any profile modification).
If I add two subfolders with the same name in an F# project I get this error:
The folder strucure is:
<ItemGroup>
<Compile Include="Test\File1.fs" />
<Compile Include="SubFolder\Test\File2.fs" />
</ItemGroup>
Does anyone know a work around?
Make sure you dont have in your project
<ItemGroup>
<Compile Include="Folder1\File1.fs" />
<Compile Include="SubFolder\Test\File2.fs" />
<Compile Include="Folder1\another.fs" />
</ItemGroup>
but instead
<ItemGroup>
<Compile Include="Folder1\File1.fs" />
<Compile Include="Folder1\another.fs" />
<Compile Include="SubFolder\Test\File2.fs" />
</ItemGroup>
(contiguous folders mentions)
This causes a bug which has been reported.
If you can isolate and reproduce a bug, please send it to fsbugs#microsoft.com, the team really looks after those pbs.
I have an XNA 3.1 content project (.contentproj) with the following:
<ItemGroup>
<Compile Include="tiles\B000N800.BMP">
<Name>B000N800</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
<Compile Include="tiles\B000N801.BMP">
<Name>B000N801</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
(... and so on ...)
</ItemGroup>
What I'd like to do is be able to specify a wildcard so that tiles\*.bmp gets compiled instead - so that I don't have to keep re-synchronising the content project when I add and remove textures from the "tiles" directory.
Does anyone know a way to do this?
Ideally the solution would ignore the hidden ".svn" directory, under "tiles". And also the content project would continue to work in Visual Studio.
You'll have to use wildcard in your item definition :
<ItemGroup>
<Compile Include="tiles\**\*.BMP"
Exclude="tiles\.svn\*">
<Name>%(Compile.Filename)</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
I found a blog post by Shawn Hargreaves that describes how to do this for XNA 1.0:
Wildcard content using MSBuild
Based on that, here is what I did which works with XNA 3.1 (and doesn't cause those weird _0 to appear):
Create a separate "tiles.proj" file with the following content:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<ItemGroup>
<WildcardContent Include="tiles\**\*.BMP" Exclude="tiles\.svn\*">
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</WildcardContent>
</ItemGroup>
<Target Name="BeforeBuild">
<CreateItem Include="#(WildcardContent)" AdditionalMetadata="Name=%(FileName)">
<Output TaskParameter="Include" ItemName="Compile" />
</CreateItem>
</Target>
</Project>
And in the original ".contentproj" file, right before </Project>, add:
<Import Project="tiles.proj" />