Edit the DefineConstants in csproj file - c#

I have csproj with the following tag:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE;SUPPORTS_ICLOUD</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Here if you see that i have added a macro called SUPPORTS_ICLOUD.
I have .txt file in that i have the following :
#define SUPPORTS_IN_APP_PURCHASE
#define BUTTON_THEME
#define SUPPORTS_TITLE
#define HAS_HTML_IMAGE_CONTENT
#define TINT_COLOR
#define NAVIGATIONTITLE_TEXT_COLOR
#define SUPPORTS_ICLOUD
As you can see in my text file i have many macros defined, now instead of passsing each macro in DefineConstants can i pass it altogether as a file or a string so that it will take all those ? Is this possible or is there any other way ?
EDIT
This is my csproj file:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0D446418-B7CD-4624-91F4-F3E382F8DD23}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>POCChild3</RootNamespace>
<AssemblyName>POCChild3</AssemblyName>
<TargetFrameworkIdentifier>WindowsPhone</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<SilverlightApplication>true</SilverlightApplication>
<SupportedCultures>
</SupportedCultures>
<XapOutputs>true</XapOutputs>
<GenerateSilverlightManifest>true</GenerateSilverlightManifest>
<XapFilename>POCChild3_$(Configuration)_$(Platform).xap</XapFilename>
<SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
<SilverlightAppEntry>POCChild3.App</SilverlightAppEntry>
<ValidateXaml>true</ValidateXaml>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Release\</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<MacroFile>Macros.txt</MacroFile>
</PropertyGroup>
<Target Name="Build">
<ReadLinesFromFile
File="$(MacroFile)" >
<Output
TaskParameter="Lines"
ItemName="MacrosFromFile"/>
</ReadLinesFromFile>
<CreateProperty
Value="#(MacrosFromFile->Replace('#define ', ''))">
<Output
TaskParameter="Value"
PropertyName="FileDefineConstants" />
</CreateProperty>
<CreateProperty
Value="$(DefineConstants);$(FileDefineConstants)">
<Output
TaskParameter="Value"
PropertyName="DefineConstants" />
</CreateProperty>
<Message Text="Const >> $(DefineConstants)" />
</Target>
In my MainPage.cs file;
#if SUPPORTS_ICLOUD
AppName.Text = "ABCD";
Debug.WriteLine("App type is app with main screen");
#endif

You can use ReadLinesFromFile, the CreateProperty and the item.Replace function to update your property by using the batching capabilities of the msbuild engine:
<!-- property defintion -->
<PropertyGroup>
<MacroFile>def.txt</MacroFile> <!-- the filename with your #defines -->
</PropertyGroup>
<!-- other stuff in your build file -->
<!-- import common targets near the end of your build file -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- override targets (make sure this is AFTER the import elements) -->
<!-- BeforeBuild is pre-dfined target which can be overriden -->
<Target Name="BeforeBuild">
<!-- Open the #define file and read every line in items named
MacrosFromFile
-->
<ReadLinesFromFile
File="$(MacroFile)" >
<Output
TaskParameter="Lines"
ItemName="MacrosFromFile"/>
</ReadLinesFromFile>
<!-- Create a new property called FileDefineConstants combining
every Item from MacrosFromFile
using the built-in replace statement to get
rid of the #define instruction
-->
<CreateProperty
Value="#(MacrosFromFile->Replace('#define ', ''))">
<Output
TaskParameter="Value"
PropertyName="FileDefineConstants" />
</CreateProperty>
<!-- re-create the orignal DefineConstants combining the current value
and the value from FileDefineConstants -->
<CreateProperty
Value="$(DefineConstants);$(FileDefineConstants)">
<Output
TaskParameter="Value"
PropertyName="DefineConstants" />
</CreateProperty>
<Message Text="Const >> $(DefineConstants)" />
</Target>

Related

blazor.webassymbly routing with URL parameter

I'm using a URL parameter as follows in my .razor page
#page "/VehicleBody-CategorizedData"
#page "/VehicleBody-CategorizedData/{PageNumber:int}"
Also, in my index.html page I've following JS tag:
<script src="/_framework/blazor.webassembly.js"></script>
But, when I try to use PageNumber parameter in my page, I get following error
Failed to load resource: the server responded with a status of 404 ()
I've attached console error:
Here is my project configuration:
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseBlazorWebAssembly>true</UseBlazorWebAssembly>
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.1" PrivateAssets="all" />
</ItemGroup>

Use Windows.Gaming.Input (GameInput) in Windows Form C#

I want to Use Windows.Gaming.Input (GameInput) in Windows Form project.
I found this link, But I could not add Windows.Gaming.
I have created a project in Microsoft Visual Studio 2022 (.Net 5.0), Then i after created and changed it to .Net Framework 4.8
file .csproj
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net48</TargetFramework>
<TargetPlatformVersion>10.0</TargetPlatformVersion>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<UseWpf>False</UseWpf>
<UseWindowsForms>True</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<StartupObject>Service.App</StartupObject>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>False</Prefer32Bit>
<Title>IO Service</Title>
<Description>Assembly providing.</Description>
<RootNamespace>Service</RootNamespace>
<AssemblyTitle>Service</AssemblyTitle>
<AssemblyName>Service</AssemblyName>
<LangVersion>10.0</LangVersion>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<UserSecretsId>e6074671-c86e-45e7-9fe9-7081c2cae035</UserSecretsId>
<Optimize>False</Optimize>
<FileAlignment>512</FileAlignment>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>Resources\Icon\App.ico</ApplicationIcon>
<UseApplicationTrust>False</UseApplicationTrust>
<!-- for .Net -->
<ApplicationVisualStyles>True</ApplicationVisualStyles>
<ApplicationHighDpiMode>SystemAware</ApplicationHighDpiMode>
<ApplicationUseCompatibleTextRendering>False</ApplicationUseCompatibleTextRendering>
<ApplicationDefaultFont>Microsoft Sans Serif, 8.25pt</ApplicationDefaultFont>
<AutoGenerateBindingRedirects>False</AutoGenerateBindingRedirects>
<UseVSHostingProcess>False</UseVSHostingProcess>
<ErrorReport>none</ErrorReport>
<WarningLevel>4</WarningLevel>
<Deterministic>True</Deterministic>
<DebugType>portable</DebugType>
<NeutralLanguage>en-US</NeutralLanguage>
<IsWebBootstrapper>False</IsWebBootstrapper>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Using Include="Windows.Gaming" />
</ItemGroup>
</Project>
I installed System.Runtime.WindowsRuntime, but Universal Windows was not added in the reference.
image1
image2
after add <TargetPlatformVersion>10.0</TargetPlatformVersion> Global Usings show in project Properties, I added Windows.Gaming in Global Usings but it doesn't work.
image3
image4
Does anyone know what I should do?

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.

The Visual Studio for Mac compile error: Your project file doesn't list 'win' as a "RuntimeIdentifier"

This error started occuring when I modified the .csproj contents. But after that i restored the original version. The error still persists, actually with no sensible reason.
/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Microsoft/NuGet/Microsoft.NuGet.targets(5,5): Error: Your project file doesn't list 'win' as a "RuntimeIdentifier". You should add 'win' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore.
.csproj file content:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D1B1F4F8-C9CF-4DC4-966D-DD7FF4683A1C}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>...</RootNamespace>
<AssemblyName>...</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<PackOnBuild>true</PackOnBuild>
<PackageId>...</PackageId>
<PackageVersion>0.1</PackageVersion>
<Authors>Mondonno</Authors>
<NeutralLanguage>en-US</NeutralLanguage>
<Owners>...</Owners>
<PackageProjectUrl>...</PackageProjectUrl>
<PackageReleaseNotes>...</PackageReleaseNotes>
<PackageTags>...</PackageTags>
<Title>...</Title>
<Description>...</Description>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\AirlyNet.xml</DocumentationFile>
<ConsolePause>false</ConsolePause>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
...
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
...
</ItemGroup>
<ItemGroup>
...
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
I tried to add the RuntimeIdentifier and RuntimeIdentifiers but facing the same error. Rebuilding or refreshing project have not helped.
To solve the problem i deleted obj directory from my solution folder Something was broken in it and when VS regenereted it problem was gone
Thanks to #Matt Ward who suggested this in question comments.

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